Search code examples
mongodbmeteorsetmongodb-update

Why does my update $set code remove my entire document?


Help! I don't what am doing wrong, when I try to update an existing field using the $set method the entire document gets removed.

Can you kindly point out what I am doing wrong in my code:

recipientsDetails.update({_id: "GCYmFqZbaaYD7DvMZ"}, {$set: {paymentStatus: "Approved"}});

Thanks for your help!


Solution

  • The code is correct. It's likely that your publish function for recipientsDetails contains recipientsDetails.find({paymentStatus: "Not Approved"}). Naturally, once you update the document, the document will no longer satisfy that filtering query and the document vanish from the client.