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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With