mongodb delete item from array code example
Example 1: how to delete subdocument array object mongodb
db.getCollection('profilesservices').updateOne({_id: ObjectId("60391a9eefdb7c17bd84c0b1")},
{
$pull: { "volunteerExperiences": {_id: ObjectId("60392e7595bb2d87689aca62")} }
}
)
Example 2: Mongodb Remove array element by index
db.example.update({}, [
{$set: {field: {
$concatArrays: [
{$slice: ["$field", P]},
{$slice: ["$field", {$add: [1, P]}, {$size: "$field"}]}
]
}}}
]);