Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor insert creating a weird _id value

Tags:

mongodb

meteor

So, I created some simple app to play with Meteor in order to learn it, and everything worked just fine a few weeks ago. But, after coming back from my vacation I updated meteor to the latest version and now all of a sudden, the insert method creates some weird _id values.

Namely, I populate my database with random values and the _id values are all proper 24 character hexadecimal strings like 562a3d8de2547280a275088a and so on. For that I use mongo insert like this:

db.simpletable.insert({ name: 'LbDM7kbZf', email: '[email protected]', age: 32 });
db.simpletable.insert({ name: 'I6UClhz', email: '[email protected]', age: 44 });
db.simpletable.insert({ name: 'XeE3vNz', email: '[email protected]', age: 33 });
...

However, when I call the .insert from Meteor, the _id value is a 17 character string like this tJ3PXRmjderbu9oKF and on the client I get the following error:

Uncaught Error: Invalid hexadecimal string for creating an ObjectID

I have no idea how to fix this or even where to look since the insert is painfully simple:

SimpleTable = new Mongo.Collection("simpletable");

SimpleTable.insert({
    name: aObj.name,
    email: aObj.email,
    age: aObj.age
});

enter image description here

like image 711
Predrag Stojadinović Avatar asked May 29 '26 07:05

Predrag Stojadinović


1 Answers

Adding , { idGeneration: 'MONGO' } fixed the problem:

SimpleTable = new Mongo.Collection("simpletable", { idGeneration: 'MONGO' });

Thanks B. Clay Shannon for the link to https://stackoverflow.com/a/33228422

like image 169
Predrag Stojadinović Avatar answered May 31 '26 06:05

Predrag Stojadinović



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!