Closed aldaMarMu closed 2 years ago
@aldaMarMu findAndModify is deprecated in all new drivers. we will also remove this method in future. use either one of findOneAndUpdate
, findOneAndReplace
or findOneAndDelete
Hi @erfanium, thank you for your answer.
If I try to use findOneAndUpdate
it gives me an error too: findOneAndUpdate is not a function
.
It seems that the collection object does not have that method. I have checked in https://github.com/denodrivers/mongo/blob/main/src/collection/collection.ts and I can see findAndModify
but not findOneAndUpdate
.
Oh damn, we have forgot to implement these methods. for now check this
const newCenter = await db.collection("centers").findAndModify({
_id: new ObjectId("62e7e66fdfa1d9392721647b"),
},{
update: { $set: {name: "test"}},
new: true
});
Hi @erfanium, thank you very much. It works!
I will use findAndModify
until findOneAndUpdate
is available.
Hello,
I am trying to use
findAndModify
to update one document in mycenters
collection but it gives me the following error:MongoError: {"ok":0,"errmsg":"Either an update or remove=true must be specified","code":9,"codeName":"FailedToParse"}
This is the code I used:
If I execute the same query on mongo shell or with a mongo client, it works perfectly.
Thank you!