Predrag Stojadinović
Predrag Stojadinović

Reputation: 3669

Meteor insert creating a weird _id value

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

Upvotes: 3

Views: 579

Answers (2)

Predrag Stojadinović
Predrag Stojadinović

Reputation: 3669

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

Upvotes: 5

Ryan W
Ryan W

Reputation: 6173

That is the ObjectId auto generated from MongoDB, you can use it as the identifier or primary key of your data

Upvotes: 1

Related Questions