How to find documents in mongodb where some fields are not null?

by darrion.kuhn , in category: MySQL , 3 months ago

How to find documents in mongodb where some fields are not null?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 3 months ago

@darrion.kuhn 

To find documents in MongoDB where some fields are not null, you can use the $ne operator to specify that the field is not equal to null.


Here's an example query to find documents where the "field1" and "field2" are not null:

1
2
3
4
db.collection.find({
  field1: { $ne: null },
  field2: { $ne: null }
})


This query will return all documents in the collection where both "field1" and "field2" are not null. You can customize this query based on your specific requirements and the fields you want to check for null values.

Related Threads:

How to query for a null fields with graphql?
How to exclude null fields in apollo graphql?
How to count documents in MongoDB using PHP?
How to mark documents as marked/deleted in mongodb?
How to concatenate arrays from multiple documents in mongodb?
How to stop insertion of duplicate documents in a mongodb collection?