how to delete subdocument array object mongodb
db.getCollection('profilesservices').updateOne({_id: ObjectId("60391a9eefdb7c17bd84c0b1")},
{
$pull: { "volunteerExperiences": {_id: ObjectId("60392e7595bb2d87689aca62")} }
}
)
how to delete subdocument array object mongodb
db.getCollection('profilesservices').updateOne({_id: ObjectId("60391a9eefdb7c17bd84c0b1")},
{
$pull: { "volunteerExperiences": {_id: ObjectId("60392e7595bb2d87689aca62")} }
}
)
mongodb remove from array
// query
db.stores.update(
{ },
{ $pull: { fruits: { $in: [ "apples", "oranges" ] }, vegetables: "carrots" } },
{ multi: true }
)
// sample data
{
_id: 1,
fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ],
vegetables: [ "carrots", "celery", "squash", "carrots" ]
}
{
_id: 2,
fruits: [ "plums", "kiwis", "oranges", "bananas", "apples" ],
vegetables: [ "broccoli", "zucchini", "carrots", "onions" ]
}
$pull mongoose
TemplateDoc.findOneAndUpdate(
{ userId: _id },
{ $pull: { templates: { _id: templateid } } },
{ new: true }
)
.then(templates => console.log(templates))
.catch(err => console.log(err));
how to remove an array element by its index in mongodb
> db.removeArrayElementByItsIndexDemo.update({}, {$unset : {"InstructorSubject.2" : 1 }});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
Mongodb Remove array element by index
db.example.update({}, [
{$set: {field: {
$concatArrays: [
{$slice: ["$field", P]},
{$slice: ["$field", {$add: [1, P]}, {$size: "$field"}]}
]
}}}
]);
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