Mongo: find items that don't have a certain field

后端 未结 2 2011
情话喂你
情话喂你 2020-12-07 15:09

How to search for documents in a collection that are missing a certain field in MongoDB?

2条回答
  •  时光取名叫无心
    2020-12-07 16:09

    Yeah, it's possible using $exists:

    db.things.find( { a : { $exists : false } } ); // return if a is missing
    

    When is true, $exists matches the documents that contain the field, including documents where the field value is null. If is false, the query returns only the documents that do not contain the field.

提交回复
热议问题