mongodb updateone
db.<collection>.updateOne({ id : 8400704 },{ $set: { name : "John" } })
mongodb updateone
db.<collection>.updateOne({ id : 8400704 },{ $set: { name : "John" } })
updateone mongodb examples
const query = { "name": "football" };
const update = {
"$push": {
"reviews": {
"username": "tombradyfan",
"comment": "I love football!!!"
}
}
};
const options = { "upsert": false };
itemsCollection.updateOne(query, update, options)
.then(result => {
const { matchedCount, modifiedCount } = result;
if(matchedCount && modifiedCount) {
console.log(`Successfully added a new review.`)
}
})
.catch(err => console.error(`Failed to add review: ${err}`))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us