Element Operators

Handle situations where:

  • Detect the presence or absence of a field.

  • Different value types in the same field.

๐Ÿ“Œ $exists

List documents that have a specific field. The value for this operator can be true or false.

db.movieDetails.find({โ€œmpaaRatingโ€: {$exist: true}})

If you use a filter to check the null value, to list documents that either have that field set to null or do not have that field.

๐Ÿ“Œ $type

List documents that have a field with a specific type of value.

db.movieDetails.find({โ€œviewerRatingโ€: {$type: โ€œintโ€}})

Last updated