Targeting the documents using ID

Next up, I'm going to write the other statement. We're going to target the Users collection once again. Now, we're going to go ahead and use the findOneAndDelete method. In this particular case, I am going to be deleting the Todo where the _id equals the ObjectId I have copied to the clipboard, which means I need to create a new ObjectID, and I also need to go ahead and pass in the value from the clipboard inside of quotes.

db.collection('Users').deleteMany({name: 'Andrew'});

db.collection('Users').findOneAndDelete({
  _id: new ObjectID("5a86978929ed740ca87e5c31")
})

Either single or double would work. Make sure the capitalization of ObjectID is identical to what you have defined, otherwise this creation will ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.