Reading Documents

🤓 Reading Documents: Scalar Fields

đź“Ś Equality filters

db.movies.find({category: "PG-13", year: 2020, “wind.type”: “C”})

Use dot notation when dealing with nested documents.

🤓 Reading Documents: Array Fields

  • If you need the same array:

db.movieDetails.find({"writers":["Ethan Coen", "Joel Coen"]})
  • If you want the element just to be part of the array:

db.movies.find({“cast”: “Jeff Bridges”})
  • If you want the element to be in a specific position in the array:

db.movies.find({“cast.0”: “Jeff Bridges”})db.movies.find({category: "PG-13", year: 2020, “wind.type”: “C”})

🤓 Cursors

The find method returns a cursor. By default, it is iterated up to 20 times.

At the shell after getting yput first 20 results, you will get the option to write “it” which is an abbreviation to iterate through the cursor.

🤓 Projections

This limit the fields that are returned in results documents. To explicitly include fields use 1, to exclude fields use 0.

db.movies.find({“cast”: “Jeff Bridges”},{“title”: 1})

Last updated