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 - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01