Am 07.12.2015 um 03:08 schrieb infinityplusb:
So in Mongodb (which I am relatively new to) I can do :
db.users.update({name: "bob"},{$addToSet: {thing: "more stuff"}})
to add an a new value pair to
bob
, in this instance a value"more stuff"
for the new item"thing"
.I am trying to do this in my vibe app but can't seem to figure the syntax.
I have tried multiple different things like:string updateString = "more stuff"; userCollection.update(["name": s.userName.serializeToBson], [ "$addToSet": [ ["thing": updateString.serializeToBson ] ] ] );
but this keeps returning
Modifiers operate on fields but we found a Array instead. For example: {$mod: {<field>: ...}} not {$addToSet: [ { thing: "more stuff" } ]
Is this something I can achieve?
And can someone guide me towards what I can do to achieve this?Regards
Brian
You just added one pair of []
to much during the translation. This
should work:
string updateString = "more stuff";
userCollection.update(["name": s.userName],
[
"$addToSet": [
"thing": updateString
]
]
);