user2180794 user2180794 - 7 months ago 12
Node.js Question

How to find all documents with a particular filed

I have the following code, but this is pulling all the documents and showing the two mentioned fields. But I want to get only those documents which have these fields.

.get(function(req, res) {
partment.find({},'unitID UnitType',function(err, apartments) {
if (err)

Any Idea how I can do that ?


Use the $exists operator:

payment.find({unitId: {$exists: true}, UnitType: {$exists: true}}, ...)