I have a meteor method that makes the following call:
Groups.update("thesamegroupId", {
$addToSet: {
contacts: {
name: 'somestring',
email: "anotherstring",
phone: "anotherstring",
_id: "anotherstring"
}
}
});
And will insert an empty object into the contacts array. Using an identical query in the meteor mongo console however produces a different result.
db.groups.update("thesamegroupId", {
$addToSet: {
contacts: {
name: 'somestring',
email: "anotherstring",
phone: "anotherstring",
_id: "anotherstring"
}
}
});
Will correctly insert the described object onto the contacts array.
I've tried for two hours to google foo this, and have come up with nothing. Any help would be appreciated, do not hesitate to ask for more info if needed.
SOLVED: This was caused by my usage of the simple schema package, I did not declare the properties on the object in the contacts array, which caused Simple Schema to clean the objects into empty objects, because the name, email, phone, and _id, properties were not properly declared
The following code is necessary for $addToSet to function:
collectionName.arrayField.$.objectProperty: {
type: <type>
}
For every property you tend to have on the object, otherwise it will be stripped.
Most helpful comment
SOLVED: This was caused by my usage of the simple schema package, I did not declare the properties on the object in the contacts array, which caused Simple Schema to clean the objects into empty objects, because the name, email, phone, and _id, properties were not properly declared
The following code is necessary for $addToSet to function:
For every property you tend to have on the object, otherwise it will be stripped.