Laravel 'like' 查询与 MongoDB 连接

Laravel #39;like#39; query with MongoDB connection(Laravel like 查询与 MongoDB 连接)
本文介绍了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 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Why can#39;t I update data in an array with foreach loop?(为什么我不能用 foreach 循环更新数组中的数据?)
Foreach for arrays inside of an array(Foreach 用于数组内的数组)
PHP array get next key/value in foreach()(PHP 数组在 foreach() 中获取下一个键/值)
Using preg_match on a multidimensional array to return key values arrays(在多维数组上使用 preg_match 返回键值数组)
php foreach as key, every two number as a group(php foreach 为key,每两个数字为一组)
Treat a PHP class that implements Iterator as an array(将实现 Iterator 的 PHP 类视为数组)