Update meteor collection with traditional identifier

I am trying to do a simple update

Collection.update(id, {$set:{name:value}}); 

or even

 Collection.update({'_id':id}, {$set:{name:value}}); 

But the collection will not be updated if id is the traditional mongodb identifier. This seems to work only with the self-identification of unique identifiers. How can I fix this. Is it possible for a meteorite to adopt its own mango identifier structure?

+8
mongodb meteor
source share
2 answers

It is possible to convert your identifier into a mongodb object (on the server side) using the new ObjectID and subsequent update.

 var ObjectID, require; require = __meteor_bootstrap__.require; ObjectID = require("mongodb").ObjectID; Meteor.methods({ SomeUpdate: function(upd) { var id; id = new ObjectID(upd['_id']); return SomeDB.update({ _id: id }, { $set: { field: value } }, function(res) { return console.log(res); }); } }); 
+6
source share

You are right: the Meteor DDP protocol does not support types other than JSON, such as Mongo ObjectId . We know that this is a problem: our oldest open problem and it is on our roadmap .

Despite the fact that there are certain β€œeasy” quick fixes that would solve this problem, we would prefer to do this in the context of expanding our protocol to handle types other than JSON (dates, binary drops, etc.), and undefined short-term hacking.

+7
source share

All Articles