I’m nearing the end of chapter 6 in the Getting MEAN book and writing a REST function to delete locations from Mongo using Mongoose.
The book recommends using findOneAndRemove(), while the Mongoose Guide recommends delete operations.
Some further reading of findOneAndDelete() gives this weak recommendation:
Some further reading of findOneAndDelete() gives this weak recommendation:
This function differs slightly from Model.findOneAndRemove() in that findOneAndRemove() becomes a MongoDB findAndModify() command, as opposed to a findOneAndDelete() command. For most mongoose use cases, this distinction is purely pedantic. You should use findOneAndDelete() unless you have a good reason not to.
Searching around the site further shows that ‘remove’ operations are deprecated in favor of ‘delete’ operations. AHA.
Replace remove() with deleteOne() or deleteMany()