Answer the question
In order to leave comments, you need to log in
How to change field in mongodb?
Good day.
There is a document with the isWorking field, which can be 1 or 0.
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}});
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question