问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/27401844/why-is-meteor-adding-objectid-around-the-id-field-since-today