If I have this document in a collection, how can I do a partial insert?
Collection
{
"_id" : "123",
"title" : "Green Tree",
"detail" : [
{
"title" : "Just a title",
"content" : "Content",
"reference" : 456
}
]
}
If I have a object with the same first level title, the just the detail should be added. So if I would add those two objects:
var newObject_1 = {
"title" : "Green Tree",
"detail" : [
{
"title" : "Just another title",
"content" : "And another content",
"reference" : 456
}
]
}
var newObject_2 = {
"title" : "Red Car",
"detail" : [
{
"title" : "title",
"content" : "content",
"reference" : 456
}
]
}
Collection.insert(newObject_1);
Collection.insert(newObject_2);
The result should be
{
"_id" : "123",
"title" : "Green Tree",
"detail" : [
{
"title" : "Just a title",
"content" : "Content",
"reference" : 456
},
{
"title" : "Just another title",
"content" : "And another content",
"reference" : 456
}
]
}
{
"_id" : "124",
"title" : "Red Car",
"detail" : [
{
"title" : "title",
"content" : "content",
"reference" : 456
}
]
}
If also the details have the same content, nothing should happen at all. If the title is different I just do Collection.insert(newObject);
to add the data completly.