Laravel #39;like#39; query with MongoDB connection(Laravel like 查询与 MongoDB 连接)
问题描述
我在 laravel 'like' 查询中遇到问题.我在 Laravel 上有一个 MIS,在 MongoDb 上有数据库.现在我的数据库有一个名为 kw 的表,带有像 cars%20in%20London 这样的 urlencoded 关键字,现在我的查询给出了 cars 或 的准确结果>cars%20in%20London 但是当我搜索 cars%20in 时,我得到 0 个结果!这就是在查询中使用 laravel 'like' 的方式,但 Mongo 使用/.m./形式,我该如何使其工作.这是我的模型函数
I am facing an issue in laravel 'like' query. I have a MIS on laravel with databases on MongoDb. Now my DB has a table named kw with urlencoded keywords like cars%20in%20London, Now my query gives accurate results for cars or cars%20in%20London but when I search cars%20in I get 0 results! This is how laravel 'like' is used in query but Mongo uses /.m./ form, How can I make this working. Here is my Model function
public static function selectKeywordIncomplete($keyword) {
$search_volume_incomplete = searchVolume::where('kw','like','%'.$keyword.'%')->orwhere('kw','=',$keyword)->where('status','=',1)->paginate(20);
return $search_volume_incomplete;
}
推荐答案
因为在 mongoDb 中没有like"这样的东西,所以我寻找了 Mongodb regex,但是 mongoDB 的 laravel regexp 很有魅力,这是有效的查询.http://jenssegers.be/projects/laravel-mongodb
well as there is no such thing as 'like' in mongoDb, I looked for Mongodb regex, but laravel regexp for mongoDB worked as a charm, here is the query which worked. http://jenssegers.be/projects/laravel-mongodb
$search_volume_unprocessed =searchVolume::where('kw','=',$keyword)->orwhere('kw','regexp',"/.*$keyword/i")->where('status','=',1)->分页(20);
$search_volume_unprocessed = searchVolume::where('kw','=',$keyword)->orwhere('kw','regexp',"/.*$keyword/i")->where('status','=',1)->paginate(20);
这篇关于Laravel 'like' 查询与 MongoDB 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 'like' 查询与 MongoDB 连接
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
