我们有这样的数据库:
{
tags : ["key1", "key2", "key3", "car", "etc.."],
question : "some text here "
},
{
tags : ["bla1", "bla2", "bla3", "etc.."],
question : "My car is here"
}
我需要查询,这将获得包含关键字" car"
的两行我试过了:
db.some.find(
'$or' : [ ["tags" : "car" ], [ "$text" : [ "$search" : "car" ] ] ]
);
"问题"是文本索引
答案 0 :(得分:3)
除非您需要使用$text
,否则您可以使用普通$regex
:
db.some.find({ $or:[ {tags:"car"}, {question:/car/} ] })