1.The CRUD method surface
Nine methods cover CRUD in practice: insertOne/Many create, find/findOne read, updateOne/Many change fields, replaceOne swaps a whole document, deleteOne/Many remove. Each has a "One" and, where it makes sense, a plural form.
Key features
- insertOne/insertMany create; find/findOne read; updateOne/updateMany change fields
- replaceOne swaps a whole document, keeping only _id; there is no replaceMany
- deleteOne/deleteMany remove documents matching a filter
- find() returns a cursor; findOne() returns one document (or null) directly
- Every method except insert takes a filter as its first argument
The nine CRUD methods
- Create
- insertOne — one document
- insertMany — many documents
- Read / Update / Delete
- find / findOne — all / first match
- updateOne / updateMany — first / all matches
- deleteOne / deleteMany — first / all matches
Command
db.<collection>.<method>(<filter>, <update or doc>, <options>)insertOne/Many, find/findOne, updateOne/Many, replaceOne, deleteOne/Many. "One" stops at the first match — it does not mean "the only match."