| 语法 | db.collection.find(filter, projection) |
|---|---|
| 默认行为 | 返回游标,mongosh 打印前 20 条 |
| 投影 | {sku:1, qty:1, _id:0} 只保留列出的字段 |
组合示例
组合示例
db.orders.find({ status: "paid", qty: { $gte: 2 } }, { sku: 1, qty: 1, _id: 0 })find() 本身不发起查询,链式方法(sort/limit)或迭代游标时才真正取数。
find(filter, projection) 返回游标:filter 支持嵌套字段与各类操作符,projection 控制返回字段(默认总是带 _id)。
| 语法 | db.collection.find(filter, projection) |
|---|---|
| 默认行为 | 返回游标,mongosh 打印前 20 条 |
| 投影 | {sku:1, qty:1, _id:0} 只保留列出的字段 |
db.orders.find({ status: "paid", qty: { $gte: 2 } }, { sku: 1, qty: 1, _id: 0 })