0 votes
1 view
in SQL by (47.7k points)

Is there a way to specify a condition of "where the document doesn't contain a field"?

For example, I want to only find the first of these 2 because it doesn't have the "price" field.

{"fruit":"apple", "color":"red"} 

{"fruit":"banana", "color":"yellow", "price":"2.00"} 

1 Answer

0 votes
by (107k points)

To find a document by non-existence of a field in MongoDB you should try the $exists operator:

db.mycollection.find({ "price" : { "$exists" : false } })

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 13 in SQL by Sammy (47.7k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...