My goal is to add new data into an existing document:
Graph.update(
{ id: id },
{
$push: {
tooltips: {
element: Session.get('tooltipID'),
text: text
}
}
}
);
Everything is going smoothly, however, I am encountering an issue where if there is already existing data in tooltips, instead of adding a new object, I need it to update the existing one. This is because each element (tooltipID) should have a unique object.
I want to prevent duplicate entries for the same element-value in tooltips.
{
"_id" : "c4bKur6TKcgFHGLZZ",
"data" : "[]",
"tooltips" : [
{
"element" : "2d4edaaf",
"text" : "Lorem"
},
{
"element" : "2d4edaaf",
"text" : "ipsum"
}
]
}
However, it should be allowed to have multiple objects in tooltips as long as the element is unique...
I attempted to include upsert:true
in the update() function, but unfortunately, it did not work as intended.