Mongo DB find by field name with any value

前端 未结 2 1805
栀梦
栀梦 2020-12-10 12:14

I am trying to find all documents that have this field, it doesn\'t matter what exact value it contains; I am only interested in the existence of it.

Here is an exam

相关标签:
2条回答
  • 2020-12-10 12:30

    You're probably looking for the $exists operator:

    db.collection.find({ "payload.discount": { $exists: true } })
    
    0 讨论(0)
  • 2020-12-10 12:35

    There's a $exists operator for that:

    db.collectionName.find({"payload.discount": {$exists: true}})
    
    0 讨论(0)
提交回复
热议问题