Meteor Collection Document IDs: Random.id() or Meteor.Collection.ObjectID()
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.
Related videos on Youtube
chris
Updated on June 15, 2022Comments
-
chris almost 2 years
When I insert documents into my Meteor collections, they have an
_id
with the form ofRandom.id
:Random.id(); // "wjQyQ6sGjzvNMDLiJ"
When I insert documents into those same collections directly from MongoDB, they have an
_id
in the form ofMeteor.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]