Reputation: 36620
Currently working on a NodeJS backend with mongoDB. I'm trying to update an Object in mongoDB using NodeJS driver:
"mongodb": "^3.0.2",
I am using the findOneAndUpdate
query and have tried the following syntax:
First syntax:
updatedPlayerData = await db.db(MDBC.db).collection(MDBC.pC).findOneAndUpdate({
'username': req.body.username
}, {
$set: {
[profession.city]: '',
[profession.organisation]: '',
[profession.profession]: ''
}
}, { returnOriginal: false });
Second syntax:
updatedPlayerData = await db.db(MDBC.db).collection(MDBC.pC).findOneAndUpdate({
'username': req.body.username
}, {
$set: {
profession: {
city: '',
organisation: '',
profession: ''
}
}
}, { returnOriginal: false });
Also have tried a bunch of other stuff. Can't seem to update the object properly. How can I properly update an object?
Upvotes: 0
Views: 65
Reputation: 136
You can try this :
db.db(MDBC.db).collection(MDBC.pC).findOneAndUpdate({
'username': req.body.username
}, {
$set: {
'profession.city': '',
'profession.organisation': '',
'profession.profession': ''
}
}, { returnOriginal: false });
Upvotes: 2