I'm confused. I tried to use the findAndModify function of a collection in NodeJS as it was stated in the official MongoDB documentation:
db.collection('myColl').findAndModify(
{
query: {
itemId: ObjectID(itemId),
requesterId: requesterId
},
remove: 1
},
function(err, found){
console.log(err, found);
});
It works fine in the console. But in NodeJS I retrieve an error. The error message told me, I have to provide at least one update or remove. There were some similar questions here on StackOverflow where one of the answers mentioned to use findAndRemove instead.
Okay, but as I searched for a documentation for findAndRemove I haven't found anything helpful. Also, my IDE (WebStorm) marks that method as deprecated. Through the autocomplete, I've also found the function findOneAndDelete which isn't marked as deprecated and seems to do what I want, but I cannot find anything about that function.
Since, I am quite new to NodeJS as well as MongoDB, this stuff is really confusing and I'm very disappointed of this documentation.
My question is: What is the background? Where can I find a useful documentation for the JavaScript API of MongoDB or how to use the MongoDB documentation correctly? Where can I get information on the above-mentioned method?
var ObjectID = require('mongodb').ObjectID?require('mongodb')) 2. Yes, I've included ObjectID