Reputation: 315
Why does Meteor.js use it's own algorithms for IDs?
Why doesn't it use MongoDB's ObjectId()?
Upvotes: 30
Views: 15319
Reputation: 1303
Since 0.9.1 Meteor suggesting to use Mongo.ObjectID
instead of Meteor.Collection.ObjectID
. Basically both are same.
Check history.md for more changes in naming conventions.
Upvotes: 5
Reputation: 75945
Meteor uses the same method for object id's if you choose to use it:
Meteor.Collection.ObjectID()
is the same as MongoDB's ObjectID
Its just under the Meteor.Collection
name. It uses EJSON to hold object id's in ordinary JSON to the client end. Because basically there are 2 databases with meteor
Minimongo
This is a sort of cache of mongodb on the client end. The data is downloaded from the main mongodb on the server to this one when the browser loads up. When changes are made they are pushed up to the server.
Server MongoDB
This is the original mongodb from 10gen on the server
So because of these two databases Meteor needs to wrap mongodb functionality in Meteor.Collection
and let you use the same code on both the client and server.
By default meteor won't use Object IDs it'll use sort of random alphanumeric text. This is done so you can easily use ID's in your URL's and ID's in your html attributes.
If you do use new Meteor.Collection.ObjectID()
you will get an ObjectID
object that will use mongodb's specification of ObjectID on the server end. The timestamp value in the Object ID isn't held up but this shouldn't really do any harm.
Upvotes: 37