Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is meteor adding ObjectId around the _id field since today?

Tags:

meteor

Maybe I'm completely wrong, but since projects that I start today, when I use meteor mongo to connect directly to the mongodb, and insert a record (with mycol.insert(..) the _id field is surrounded with ObjectId("12345555..."). When adding a record from code this is not the case. So, records added via Meteor Mongo are not recognised inside the app any longer. I have done this in the past so often... what's happening here?

like image 458
paul van bladel Avatar asked Dec 10 '14 13:12

paul van bladel


1 Answers

That's the MONGO way and you see this because you are using the Mongo shell. Meteor defaults to a different method (cf below) which you see when you use it programmatically. Check Meteor docs on new Mongo.Collection

idGeneration String

The method of generating the _id fields of new documents in this collection. Possible values:

  • 'STRING': random strings
  • 'MONGO': random Mongo.ObjectID values

The default id generation technique is 'STRING'

In Meteor, if you write

Steffo = new Meteor.Collection("steffo", {idGeneration: 'STRING'});

this will result in entries

{ "foo" : "bar", "_id" : "68FWFNGRAuRt82pWy" }

If you use

Paul = new Meteor.Collection("paul", {idGeneration: 'MONGO'});

you'll get

{ "foo" : "bar", "_id" : ObjectId("26cfdb5f200adfa0b55a50d3" }

The latter happens when you use Mongo shell.

like image 92
Steffo Avatar answered Nov 09 '22 21:11

Steffo