How to exact match entire document?

前端 未结 3 1285
花落未央
花落未央 2021-01-21 01:33

Exact matching subdocuments is easy, but is there a way to exact match entire document in a collection ?

I have a lot of documents with similar data, and I only need e

3条回答
  •  北海茫月
    2021-01-21 02:19

    I really don't understand your question, can you explain it ?

    If you want documents that doesnt have some fields you can use $exists.

    For example, if you have...

    {a: 1 , b: "1", c: true }
    {a: 2, b: "2", c: false}
    {a: null, b: "3" }
    

    Then db.my_collection.find({a: {$exists: true}}); finds

    {a: 1 , b: "1", c: true }
    {a: 2, b: "2", c: false}
    

    And db.my_collection.find({a: {$exists: false}}); finds

    {a: null, b: "3" }
    

提交回复
热议问题