Which method takes the filter in MongoDB?
The filter is given as the first argument to most CRUD methods, such as:
find()findOne()updateOne()/updateMany()replaceOne()deleteOne()/deleteMany()
Example:
js
db.users.find({ age: 25 }) // filter: { age: 25 }
db.users.updateOne({ name: "Alex" }, { $set: { age: 26 } })
db.users.deleteMany({ isActive: false })So: the filter is always passed as the first parameter to the method that finds, updates, or deletes documents.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.