Created
August 24, 2022 17:25
-
-
Save fgm/7e81af81c31f6c0aac4245ee29f4c3c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Insert doc: | |
sections = [ | |
{ | |
slug:"introduction", | |
title:"Introduction", | |
videos:[ | |
{"k": "v0"}, | |
{"k": "v1"}, | |
{"_id": ObjectId('abcdefghijkl')} | |
] | |
} | |
]; | |
doc = {sections: sections}; | |
// { | |
// sections: [ | |
// { | |
// slug: 'introduction', | |
// title: 'Introduction', | |
// videos: [ | |
// { k: 'v0' }, | |
// { k: 'v1' }, | |
// { _id: ObjectId("6162636465666768696a6b6c") } | |
// ] | |
// } | |
// ] | |
// }; | |
db.linkedin.insertOne(doc); | |
// Delete nested object: | |
db.linkedin.updateOne( | |
{}, | |
{ | |
$pull: { | |
"sections.0.videos": { | |
_id: ObjectId("6162636465666768696a6b6c") | |
} | |
} | |
} | |
) | |
// { | |
// acknowledged: true, | |
// insertedId: null, | |
// matchedCount: 1, | |
// modifiedCount: 1, | |
// upsertedCount: 0 | |
// } | |
// Verify: | |
db.linkedin.findOne({_id:ObjectId("6306599912d8dbd883cbb345")}) | |
// { | |
// _id: ObjectId("6306599912d8dbd883cbb345"), | |
// sections: [ | |
// { | |
// slug: 'introduction', | |
// title: 'Introduction', | |
// videos: [ { k: 'v0' }, { k: 'v1' } ] | |
// } | |
// ] | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment