Finding Documents
Load the whole recipe collection with insertMany, then find exactly the recipes you want: by an exact value, by a range with comparison operators, by several conditions at once, and by whether a field is there at all.
Updated
Adding Documents
- Adding Many Documents with insertMany (Apprentice): insertMany adds a whole list of documents in one call and tells you each one's _id; a duplicate _id stops it unless you set ordered to false, and load() runs a whole file of them.
Finding Documents
- Finding Documents with find and findOne (Novice): A filter describes the documents you want, field by field; find gives back every document that matches, findOne the first one or null, and countDocuments how many there are.
- Comparison Operators: $gt, $lt, $in and More (Apprentice): Comparison operators let a filter ask for more than an exact value, such as less than 30 minutes, a range between two numbers, one of a list of cuisines, or anything but one value.
- Combining Conditions: $and, $or and $not (Apprentice): Two fields in one filter already mean "and"; $or matches when any of its conditions does, $and holds conditions that can't share one document, and $not and $nor rule documents out.
- Missing Fields, null and $exists (Apprentice): Documents in one collection don't all have the same fields; a filter for null matches a missing field too, $exists asks whether the field is there at all, and $type finds values stored as the wrong kind.
Exercise: Recipe Finder
- Exercise: Recipe Finder (Apprentice): Write six mongosh queries for Sunday Kitchen's recipe pages, from quick dinners to the recipes nobody has rated yet, and let the tests run each one on the 40 recipes and check what it finds.