reectrix
reectrix

Reputation: 8629

How do you return all documents with a value for a field in mongo?

I want to return all documents in mongo that have a value for a field. For instance, I want to return all documents where name is not null:

db.people.find({name: "not null"})

How do I do this in Mongo DB?

Upvotes: 1

Views: 64

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191799

Use $ne with null

db.people.find({name: {$ne: null}})

$exists will still find a record where name is actually null.

Upvotes: 3

Related Questions