我有一个如下集合
{
"_id" : ObjectId("55bec0793bed809b2cb658ad"),
"lock_1" : ["desc_1","desc_2"],
"lock_2" : ["desc_1"]
},
{
"_id" : ObjectId("55bec0793bed809b2cb658ab"),
"lock_1" : ["desc_1","desc_2","desc_3"],
"lock_2" : ["desc_1"]
}
{
"_id" : ObjectId("55bec0793bed809b2cb658ac"),
"lock_1" : ["desc_1"],
"lock_2" : []
},
{
"_id" : ObjectId("55bec0793bed809b2cb658ae"),
"lock_1" : [],
"lock_2" : ["desc_1"]
},
{
"_id" : ObjectId("55bec0793bed809b2cb658aj"),
"lock_1" : ["desc_3","desc_4"],
"lock_2" : ["desc_5"]
},
{
"_id" : ObjectId("55bec0793bed809b2cb658ak"),
"lock_1" : [],
"lock_2" : []
}
我使用下面的查询检索了“lock_1”和“lock_2”数组中包含“desc_1”的所有文档,返回前两个文档,这是正确的。
db.locks.find( { $and: [ {lock_1 : "desc_1"} , {lock_2 : "desc_1"} ] } )
现在,我正在尝试获取不符合上述条件的文件。我尝试使用以下查询,但它返回最后两个文档。
db.locks.find( { $nor: [ {lock_1 : "desc_1"} , {lock_2 : "desc_1"} ] } )
如何检索“desc_1”在其中一个数组中不存在或存在的文档?