How do I do a “NOT IN” query in Mongo?

前端 未结 4 1274
花落未央
花落未央 2020-11-28 10:15

This is my document:

{ 
    title:\"Happy thanksgiving\",
    body: \"come over for dinner\",
    blocked:[
       {user:333, name:\'john\'},
       {user:99         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 11:03

    See http://docs.mongodb.org/manual/reference/operator/query/nin/#op._S_nin

    db.inventory.find( { qty: { $nin: [ 5, 15 ] } } )
    

    This query will select all documents in the inventory collection where the qty field value does not equal 5 nor 15. The selected documents will include those documents that do not contain the qty field.

    If the field holds an array, then the $nin operator selects the documents whose field holds an array with no element equal to a value in the specified array (e.g. , , etc.).

提交回复
热议问题