Articles → MONGODB → $Exists In Mongodb

$Exists In Mongodb






Purpose





Syntax


db.[collection_name].find(
{
         [field]:{$exists:false
 }
}) -- returns the document(s) that does that contain the field

db.[collection_name].find(
{
         [field]:{$exists:true
 }
}) -- returns the document(s) that contains the field



Example




Picture showing the sample collection in mongodb




Picture showing the output of $exists operator in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Monday, March 4, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250