Within my mongodb database, I store collections comprising of documents and embedded documents at the posts and comments levels. One example is a post document that includes two comments as embedded documents.
{
"__v" : 0,
"_id" : ObjectId("502d7b33eac728b658000002"),
"comments" : [
{
"_id" : ObjectId("502d7b39eac728b658000003"),
"body" : "comment 1",
"votes" : 1
},
{
"_id" : ObjectId("502d7d1feac728b658000004"),
"body" : "comment 2",
"votes" : 0
}
],
"text" : "post 1",
}
My goal is to transform this data structure to align with a Backbone.js setup consisting of a PostCollection, PostModel, CommentCollection, and CommentModel, with each PostModel containing a CommentCollection. It's crucial that this structure remains intact every time a fetch() function is called on PostCollection or PostModel to synchronize from a REST API.
In addition, I seek to monitor Backbone.js "change" and "add" events on all the specified collections and models as well.
How should I proceed with approaching this task?