user2180794 user2180794 - 1 year ago 71
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 ?

Answer Source

Use the $exists operator:

payment.find({unitId: {$exists: true}, UnitType: {$exists: true}}, ...)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download