$addToSet Object

Hello,

I have really strange situation, which might be normal, but I have to ask it anyway for a hint or such.

I am using the $addToSet to update/upsert documents from a collection. The desired schema of the document is like:


{name:"XXXX",
sources:[
{name:"test1", id:"1"},
{name:"test2", id:"2"}
]
}

However, when the document is update with via update/upsert command, it is not adding/overwriting the matching record in the “sources” set, but simple overwrite the “name” property"

TestCollection.upsert({name:"XXXX"}, {$addToSet:{sources: {name"test1", id:"1"}}}))

and the result is like:


{name:"XXXX",
sources:[
{name:"test1", id:"1"},
{name:"test1", id:"2"}
]
}

in the above case it should have not updated the document, because the element is presented in the set already, but it is actually updating the next element name property. Is this normal?

This works on the server, but on the client you can’t update without an ID. Have you checked your console in the browser? When I try it on the client I get

rrorClass {error: 403, reason: "Not permitted. Untrusted code may only update documents by ID.", details: undefined, message: "Not permitted. Untrusted code may only update documents by ID. [403]", errorType: "Meteor.Error"}

on the server I see

TestCollection.upsert({name: 'XXX'},{$addToSet:{test:{test: 'three'}}})
{ numberAffected: 1, insertedId: 'h6iQgsTQn38jnvcks' }