deleteOne()

Deletes the first document that matches the filter. Returns an acknowledgment with the delete count.

Syntax

mongodb
db.collection.deleteOne(filter)

Example

mongodb
const result = await db.sessions.deleteOne({
  _id: sessionId
});
console.log(result.deletedCount); // 0 or 1

// Delete expired sessions:
await db.sessions.deleteOne({
  expiresAt: { $lt: new Date() }
});