find() retrieves documents from a MongoDB collection by applying an optional query filter. It returns a cursor rather than loading every matching document immediately, enabling on-demand, batched retrieval that reduces memory use and network bandwidth. section 4.6 section 4.13
Use find() progressively:
- Run db.routes.find() without a filter to match every document in the routes collection. section 4.6
- Supply field-value conditions such as { src_airport: 'LHR' } to select matching routes. section 4.6
- Use operators such as $in, $nin, or $not for membership, exclusion, and pattern-negation conditions; multiple fields form a compound query. section 4.6.2
- Iterate the returned cursor manually or let mongosh display and advance through results; mongosh shows up to the first 20 documents automatically. section 4.13 section 4.6
Find routes from selected airports
db.routes.find({ src_airport: { $in: ['MUC', 'JFK', 'LHR', 'DFW'] } }) returns routes whose src_airport matches any listed value. Use $nin instead to exclude those airports. section 4.6.2
const cursorVariable = db.routes.find()
Store the cursor in a variable, then iterate over matching documents as needed. section 4.13
