I
I
Ivan Ivanovich2020-10-21 18:01:28
Node.js
Ivan Ivanovich, 2020-10-21 18:01:28

How to change field in mongodb?

Good day.

There is a document with the isWorking field, which can be 1 or 0.

5f904c744d44f590347714.png

You can update the field like this: But what should I do if I just need to update this field and that's it. Those. something like this: When we just pass the name of the field, without a specific value. Crutch:updateOne({isWorking: 0}, {$set: {isWorking: 1}})


updateOne({isWorking}, {$set: {isWorking: 1}})



const test = await Config.findOne()
  await Config.findOneAndUpdate({isWorking: test.isWorking}, {$set: {isWorking: 1}});


Can this functionality be implemented somehow? Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MagnusDidNotBetray, 2020-10-21
@IwanQ

So?

const test = await Config.findOne()
await Config.findOneAndUpdate({isWorking: {$exists: true}}, {$set: {isWorking: 1}});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question