I'm trying to find out if there is a best practice on handling CRUD on nested MongoDB documents from a client application like a MEAN stack application. The answers don't have to be specific to MongooseJS or directly connecting to MongoDB in the client, it's more on the concept. How to handle CRUD on nested documents?
Here's my sample document:
{
"company":"Acme Industries",
"website":"http://www.acme.com",
"active":true,
"contacts":[
{
"firstName":"Wile",
"lastName":"Coyote",
"dateCreated":"4/3/2015",
"address":"123 Main St",
"city":"Yuma",
"state":"AZ",
"postalCode":"84938",
"phoneNumbers":[
{
"Home":"(333) 555-8958",
"Cell":"(444) 940-3484"
}
],
"emailAddresses":[
{
"Home":"wile@coyote.com",
"Work":"info@acme.com"
}
]
}
]
}
My client application will have an interface for these different forms:
- Add/Edit Company
- Add/Edit Contact
- Add/Edit Phone
- Add/Edit Email Address
I know about creating child schemas for each nested document. Is this a better way to go than simply managing the child data in each node of the root document?
It seems that this needs to be handled similarly to a relational schema, where I create 4 different CRUD scenarios for each independent area that needs to be managed. Or is there a better way? There doesn't seem to be clear documentation on how to do this.