Reputation: 189
I'm trying to update a Mongo record via Chrome's console.
Posts.update('hexidhere', {$set: {title: 'something text here'}});
The problem is with docs that were created a Mongo terminal. They were assigned an id like so (_str and _proto are nested inside the _id):
_id: LocalCollection._ObjectID
_str: '54ff06801ad15adbb3d1090'
_proto: LocalCollection._ObjectId
title: 'dummy title here'
When I added another test doc via chrome's console (not a mongo terminal) It seems to have added an ID correctly, and everything works as expected:
_id: 'EtPt9ntXtxG4qo9Tb'
title: 'dummy title here'
My question is: Does anyone know a way to make the ID always be simple HexStrings (like in the second example), or is there a correct method for accessing the nested str value in the LocalCollection (I've tried Mongo.ObjectID('hexidhere'), 'theidhere', and a whole bunch of other stuff)?
Upvotes: 1
Views: 640
Reputation: 4948
Mongo likes to use ObjectId
for _id
, Meteor opted to use String
. To learn more see the now deprecated google groups convo: https://groups.google.com/forum/#!topic/meteor-talk/f-ljBdZOwPk
To get the string of an ObjectId
use the str
method as in ObjectId("310458asdf323452").str
See here for more info: http://docs.mongodb.org/manual/reference/object-id/
Upvotes: 1