I have a record like this
{
"_id" : ObjectId("57025c35e31f7274c1195c26"),
"token" : "0ffed58b-57ed-4a2a-bb09-97c64f0f2bd2",
"key" : "silly key",
"user" : ObjectId("55e3f8fcc78dc516096dc3e2"),
"twlprofile" : "Test Blog"
}
It is the only one in the collection.
I am trying to update
and need the update to upsert if it can't find anything, so I have this code
var id = "55e3f8fcc78dc516096dc3e2";
var tokendoc = {
"token": "05c50aa0-5a8c-4fad-b27f-db64a0355b4f",
"key": "silly key",
"user": "55e3f8fcc78dc516096dc3e2",
"twlprofile": "Test Blog"
}
var tokenrecord = tokensCollection.update(
{ where: { user: id } },
tokendoc,
{ upsert: true },
function(err,tokenres){
//this part not important right now
});
which if I run it ends up inserting another document with the same user property. I have also tried using BSON.ObjectID with the id variable and it doesn't help.
How do I get this to work like a real upsert?