Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在MongoDB中,如何在文本和数组中搜索_Arrays_Mongodb_Search - Fatal编程技术网

Arrays 在MongoDB中,如何在文本和数组中搜索

Arrays 在MongoDB中,如何在文本和数组中搜索,arrays,mongodb,search,Arrays,Mongodb,Search,我们有这样的db: { tags : ["key1", "key2", "key3", "car", "etc.."], question : "some text here " }, { tags : ["bla1", "bla2", "bla3", "etc.."], question : "My car is here" } 我需要查询,这将得到两行关键字“车” 我试过: db.some.find( '$or' : [ ["tags" : "car" ], [ "$text" : [

我们有这样的db:

{
tags : ["key1", "key2", "key3", "car", "etc.."],
question : "some text here "
},
{
tags : ["bla1", "bla2", "bla3", "etc.."],
question : "My car is here"
}
我需要查询,这将得到两行关键字“车”

我试过:

db.some.find(
 '$or' : [ ["tags" : "car" ], [ "$text" : [ "$search" : "car" ] ] ]
);

“问题”是文本索引,除非您需要使用
$text
,否则可以使用纯
$regex

db.some.find({ $or:[ {tags:"car"}, {question:/car/} ] })

我认为您有语法问题(如果您是从
mongo
shell运行此程序)。试试这个:
db.some.find({'$or':[{“tags”:“car”},{“$text”:{“$search”:“car”}]})