Mongo查询未给出预期结果

时间:2015-01-26 14:39:15

标签: mongodb

我的藏品中有以下文件。

{
 "state": "approved",  
 "applicants": [   
],
 "user": "54a62c8bd334c57300d63af5", 
 "nonapplicants": [
  {
  "id": "54a630d7d334c59501d63afd"
  }
 ]
}

我正在执行以下查询以获取具有非应用程序ID“54a630d7d334c59501d63afd”或申请人ID为“54a630d7d334c59501d63afd”的文档,但它不会显示任何结果。

{"$or":[{"applicants.id":"54a630d7d334c59501d63afd","nonapplicants.id":"54a630d7d334c59501d63afd"}]}

1 个答案:

答案 0 :(得分:0)

您的查询中有错误:您的$or只有一个参数,即{"applicants.id":"54a630d7d334c59501d63afd","nonapplicants.id":"54a630d7d334c59501d63afd"}你想要的是:

{"$or":[{"applicants.id":"54a630d7d334c59501d63afd"}, {"nonapplicants.id":"54a630d7d334c59501d63afd"}

而不是:

{"$or":[{"applicants.id":"54a630d7d334c59501d63afd", "nonapplicants.id":"54a630d7d334c59501d63afd"}