Best Practices: Mutating Sub-documents (looking for guidance)


#1

I’m looking guidance. I working with two type of sub-documents. In one case I’m storing sub-documents as a series of objects like so
{
post_title: ’ '

post_comments: {
comment1_id: { },
comment2_id: { },
comment3_id: { },
},
post_id: ’ ',
}

Other times I store sub-documents in array like so,

{
post_title: ’ '

post_comments: [
{ comment1… },
{ comment2… },
{ comment3… },
],
post_id: ’ ',
}

These are two typical approaches and both have their place. Can anyone point me to code snippets for handing mutations (adding, updating, removing, reading sub-documents) for both configurations? Note, I am familiar with the basic .push() and .pop() calls, but I am looking for a library of efficient approaches to handle a range of mutations. Consider what Ramda.js and Lodash provide for nested objects and arrays, is their something of the sort for handling sub-documents?