Check that Field Exists with MongoDB
Check that Field Exists with MongoDB
You can use $ne (for “not equal”)
db.collection.find({ "fieldToCheck": { $exists: true, $ne: null } })
Try to use this:
{ "_id":"1234" "open":"Yes" "things":{ "paper":1234 "bottle":"Available" "bottle_count":40 } }
You want to know if the bottle field is present of not ?
Answer:
db.products.find({"things.bottle":{"$exists":true}})
Just try to do it:
db.getCollection('collectionName').findOne({"fieldName" : {$ne: null}})