我可以在 mongodb 查询中使用 OR 和 AND 的组合吗?
下面的代码不能按预期工作
db.things.find({
$and:[
{$or:[
{"first_name" : "john"},
{"last_name" : "john"}
]},
{"phone": "12345678"}
]});
数据库内容:
> db.things.find();
{ "_id" : ObjectId("4fe8734ac27bc8be56947d60"), "first_name" : "john", "last_name" : "hersh", "phone" : "2222" }
{ "_id" : ObjectId("4fe8736dc27bc8be56947d61"), "first_name" : "john", "last_name" : "hersh", "phone" : "12345678" }
{ "_id" : ObjectId("4fe8737ec27bc8be56947d62"), "first_name" : "elton", "last_name" : "john", "phone" : "12345678" }
{ "_id" : ObjectId("4fe8738ac27bc8be56947d63"), "first_name" : "eltonush", "last_name" : "john", "phone" : "5555" }
查询上述查询时 - 我什么也没得到!
> db.things.find({$and:[{$or:[{"first_name" : "john"}, {"last_name" : "john"}]},{"phone": "12345678"}]});
>
我正在使用 mongo 1.8.3