deleteOne and deleteMany

noun

say it: “dih-leet-WUN and dih-leet-MEN-ee” /dɪˌlitˈwʌn ænd dɪˌlitˈmɛni/

MongoDB methods that remove documents: deleteOne the first that matches a filter, deleteMany every match.

What does deleteOne and deleteMany do?

deleteOne removes the first matching document; deleteMany removes every match (all of them with {}, so be careful).

db.sessions.deleteMany({ expiresAt: { $lt: new Date() } })

In a sentence

  • “deleteMany with { expired: true } cleared out 40 old coupons.”
  • “The cancel route uses deleteOne with the order's _id.”

Level: Apprentice · More MongoDB terms at this level

Updated