Reputation: 1841
I'm developing a MEAN stack application that needs to insert a list of contacts into a single record in MongoDb.
I'm using the Node-Restful module, which is a great helper.
I'm having trouble figuring out how I would insert/embed a list of contacts into an single user's record. The alternative for me is to do a reference to another collection, but from what I've seen in Mongo, the recommendation would be to embed each contact as a subdocument within a single document.
Has anyone had experience using the Node-Restful module to do this?
https://github.com/baugarten/node-restful
Upvotes: 0
Views: 242
Reputation: 16780
You can post a object with the related sub-docs. Eg:
{ "name": "Luke Skywalker",
"films": [
{
"director": "George Lucas",
"title": "A New Hope"
},
{
"director": "George Lucas",
"title": "Attack of the Clones"
}
]
}
On my person schema I have a reference to film schema in "films" attribute. By this way you will create the document with the subdocuments in just one post.
Upvotes: 1