Reading Arrays from Documents

Explore working with arrays in MongoDB, including querying for specific values, using operators like $in, $nin, $all, and $size, to filter and manipulate array data in documents.

Understanding arrays in MongoDB

In MongoDB, an array is a list of values within a field of a document. These values can be of any data type:

  • Strings: ["reading", "cycling", "music"]

  • Numbers: [1, 2, 3, 4]

  • Objects: [ { "name": "Alice" }, { "name": "Bob" } ]

  • Nested arrays: [ [1, 2], [3, 4] ]

Visually, we can see them as below.