1TemplateDoc.findOneAndUpdate(
2 { userId: _id },
3 { $pull: { templates: { _id: templateid } } },
4 { new: true }
5 )
6 .then(templates => console.log(templates))
7 .catch(err => console.log(err));
1// query
2db.stores.update(
3 { },
4 { $pull: { fruits: { $in: [ "apples", "oranges" ] }, vegetables: "carrots" } },
5 { multi: true }
6)
7
8// sample data
9{
10 _id: 1,
11 fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ],
12 vegetables: [ "carrots", "celery", "squash", "carrots" ]
13}
14{
15 _id: 2,
16 fruits: [ "plums", "kiwis", "oranges", "bananas", "apples" ],
17 vegetables: [ "broccoli", "zucchini", "carrots", "onions" ]
18}
19
1> db.removeArrayElementByItsIndexDemo.update({}, {$unset : {"InstructorSubject.2" : 1 }});
2WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
1db.example.update({}, [
2 {$set: {field: {
3 $concatArrays: [
4 {$slice: ["$field", P]},
5 {$slice: ["$field", {$add: [1, P]}, {$size: "$field"}]}
6 ]
7 }}}
8]);
9