Arrays and Nested Fields

Arrays and Nested Fields: Fields Inside Fields: Dot Notation, Querying Arrays: One Value, $all and $size, Arrays of Documents and $elemMatch.

Updated

  1. Fields Inside Fields: Dot Notation (Apprentice): Dot notation names a field inside an embedded document, such as "nutrition.calories" in quotes, so a filter can test that one field instead of matching the whole embedded document.
  2. Querying Arrays: One Value, $all and $size (Apprentice): A filter on an array field matches when any item fits, $in matches when any item is one of a list, $all asks for every value in a list, and $size counts the items; an exact array match is rarely what you want.
  3. Arrays of Documents and $elemMatch (Journeyman): Dot notation reaches a field of every document in an array, such as "ingredients.name"; two such conditions can be met by two different items, and $elemMatch makes them hold for the same item.