Inserting record in Meteor and Mongo DB giving strange ID

I get a weird id returned after inserting a record via Meteor. I’ve seen a couple posts in SO regarding this, but I can’t make heads or tails of it. Once the record is inserted I can’t seem to update since there’s a mistmatch in id data types.

So after insert via Meteor I get an id like this “Q3GwNew4e37syDNmR” vs. and id like this “589b42005476f83e4855a398”.

I get the following error:

Error: Invalid hexadecimal string for creating an ObjectID

What am I doing wrong here?

By default Meteor uses 17 char strings as ids when inserting in Mongo. If you want to change that behaviour to match Objectid strings, you have to select the kind of id generation when defining the collection.

Look at idGeneration param in http://docs.meteor.com/api/collections.html#Mongo-Collection

1 Like