Tyler James Tyler James -5 years ago 145
Javascript Question

updateOne deleting my data [mongodb]

Alright, so I've been tinkering with this all night and I have to sleep so I'm asking here. Why is

deleting my data when it should just be updating it?

DB.collection('users').updateOne({"name":"bob"}, {"age":"20"}, (e,i) => {



, but when I go to search for
after doing this, the data is gone entirely, vanished.

My first question is why is this happening, my second is how can I update, since apparently this isn't the way to do it.

I can run find({"name":"bob"}) just fine before hand, so the data does exist before running this.

After, it is gone. Help please, my blood pressure is getting way too high.

Answer Source

Try the following:-

You need to use $set to update specific fields. {} give blank, if there is no find query.

DB.collection('users').updateOne({"name":"bob"},{$set: {"age":"20"} });

To get your answers, refer mongodb-update.

Hope this will hep you solving the problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download