Linked Questions
35 questions linked to/from Mongoose: findOneAndUpdate doesn't return updated document
6 votes
1 answer
10k views
mongoose.findOneAndUpdate returns null [duplicate]
I am using mongoose.findOneAndUpdate() method for inserting and updating a document in the collection. However if there is nothing to update in the table and a new document is created, the ...
0 votes
1 answer
2k views
MongoDB update record and fetch [duplicate]
In MongoDB (using node.js) I want to update a record and then fetch the returned record. Can I do this atomically at all? My searching suggested I could use findOneAndUpdate, however my testing with ...
0 votes
2 answers
2k views
Null error from findByIdAndUpdate [duplicate]
So I have this API method: router.delete('/circleAlertDelete/:id', function(req, res, next){ User.findOne({_id: req.params.id}).then(function(user){ var userTemp = user; var alerts = user....
0 votes
1 answer
953 views
Nodejs Mongoose | findOneAndUpdate not working properly [duplicate]
I am working on node js app using express.js and mongodb with mongoose module to handle the database. in one case I need to update a user property languages using findOneAndUpdate method. this ...
0 votes
0 answers
457 views
findByIdAndUpdate does not work in express, but does work in mongo tool [duplicate]
I am a beginner of mongodb and express, now I am trying to update some data. I do not think there is something wrong in my code, when I turn debugging on, the following db operation is printed out and ...
0 votes
0 answers
339 views
mongoose update item in array object [duplicate]
I have a data similar to this: "_id" : ObjectId("5aff8a15fac9291cb0477c87"), "user" : ObjectId("5adbf5ffd08592252c0efeba"), "createdTime" : ISODate("2018-05-19T02:21:09.943Z"), "...
2 votes
1 answer
109 views
Having trouble finding/or implementing the correct mongoDb method to find and update subdocument [duplicate]
I'm trying to update a specific field in a subdocument based on its Id and the Id of the parent document. I'm new to this so I may be misunderstanding the mongoDb documentation but as far as I can ...
0 votes
0 answers
114 views
Update a mongodb document and get the updated document [duplicate]
Using Express and MongoDB, how can I update a document, then get that updated document? The following code will find the profile document with the given user.id, then remove the experience with the ...
0 votes
0 answers
102 views
findOneAndUpdate() returns null if I don't supply two values [duplicate]
I rarely ask someone for help, but in this particular case I can't figure out what to do. I would like to handle PUT requests to my API to update either "name" or "dllFile" or both values in my ...
0 votes
0 answers
84 views
mongodb: findOneAndUpdate not working [duplicate]
I started working with Mongoose with Express.js. I am trying to insert a record into the database and update it if it exists. I am using findOneAndUpdate for this purpose. But it does not work. Data ...
0 votes
0 answers
20 views
how to get updated document from mongodb [duplicate]
i'm using findOneAndUpdate function from mongoose and in the nodejs i am updating a record now i want to send the updated data in response but as mongoose stop supporting callback function in updates ...
53 votes
9 answers
27k views
How to get updated document back from the findOneAndUpdate method?
I am using MongoDB with node js , i used npm install mongodb I want to update an existing document and return the updated document , the document is updated correctly . but it returns the old ...
1 vote
4 answers
2k views
db.collection.findOneAndUpdate () is not returning the "updated" document
following the official manual, db.students2.findOneAndUpdate( { _id : 1 }, [ { $set: { "total" : { $sum: "$grades.grade" } } } ], // The $set stage is an alias for ``$...
0 votes
1 answer
1k views
How to Update only passed value in mongodb using mongoose?
I have built an API that updates records in MongoDB using mongoose, but currently what happening is if I am passing only 4 field values in the JSON file of postman and try to update then all the ...
0 votes
3 answers
2k views
mongoose.findoneandupdate() says updated successfully but no changes occur in database
User is the basic schema I created with a name, email, and password. But when I try to update it no errors occur yet the collection in mongodb doesn't change. Tried the {strict: false} option on the ...