Find documents with arrays not containing a document with a particular field value in MongoDB

前端 未结 2 1312
一个人的身影
一个人的身影 2020-12-05 03:56

I\'m trying to find all documents that do not contain at least one document with a specific field value. For example here is a sample collection:

{  _id : 1         


        
2条回答
  •  隐瞒了意图╮
    2020-12-05 04:27

    Using $nin will work, but you have the syntax wrong. It should be:

    db.collection.find({'docs.foo': {$nin: [1]}})
    

提交回复
热议问题