Sign In Register

How can we help you today?

Start a new topic
Answered

MongoDB update return value

I make an update of a mongoDB document in cloud code.

I need to know if the update did an update or if it didn't update because of the condition.


The return value of the update function is true or false, and returns true even if no document was updated.

In other word, I would like to test the "NO RESULT" that I get when I make the update from NoSQL.


My update : 

myCollection.update({"_id": myId, { "_lock": { $exists: false }}, {$set:{"_lock":true}});


I can't read the document afterwards, because the _lock field will exists whatever the update updated or not the document.


Thanks for your help !


Best Answer

Hi Eric,


You could use findAndModify in place of update with the same parameters, this will return the document which matches the query provided, from which you can get the id.


Try this out and let us know how it works for you.


Regards,

Vinnie


Answer

Hi Eric,


You could use findAndModify in place of update with the same parameters, this will return the document which matches the query provided, from which you can get the id.


Try this out and let us know how it works for you.


Regards,

Vinnie

Thanks for the tip :)

Login to post a comment