When I insert documents into my Meteor collections, they have an _id
with the form of Random.id
:
Random.id();
// "wjQyQ6sGjzvNMDLiJ"
When I insert documents into those same collections directly from MongoDB, they have an _id
in the form of Meteor.Collection.ObjectID
.
new Meteor.Collection.ObjectID();
// LocalCollection._ObjectID {_str: "b105582bc495617542af18e9"…}
Why does my app use Random.id
? Is this a legacy setting?
Meteor versions when I created my app:
[email protected]
[email protected]
When I insert documents into my Meteor collections, they have an _id
with the form of Random.id
:
Random.id();
// "wjQyQ6sGjzvNMDLiJ"
When I insert documents into those same collections directly from MongoDB, they have an _id
in the form of Meteor.Collection.ObjectID
.
new Meteor.Collection.ObjectID();
// LocalCollection._ObjectID {_str: "b105582bc495617542af18e9"…}
Why does my app use Random.id
? Is this a legacy setting?
Meteor versions when I created my app:
[email protected]
[email protected]
Share
Improve this question
asked Mar 27, 2015 at 14:21
chrischris
7272 gold badges5 silver badges16 bronze badges
1 Answer
Reset to default 16When creating your Meteor collection programatically from your application, you have the ability to specify an option that determines what type of ID generation method is used to generate new IDs for documents in that collection. By default, a random string generation function is used if no option is specified. Check out the Meteor documentation to see exactly what I am talking about. If you do not specify the option, Meteor simply uses the random package in order to generate these ID strings. If you check the link, you will see that the first item in the list is a random ID generation function. This is where the Random.id()
function is being called. Obviously, going directly to MongoDB bypasses this possible flow of logic, resulting in the MongoDB type of ID string.