Hello. I’m trying to figure out how to generate an
_id in the same that Meteor does.
For context, I want to do this because I’m following some Domain-Driven Design tutorials, and I notice they generate a unique id for entities before that entity is persisted to the database. For more context,
- I’m using Meteor 1.8.2
- I’m using GraphQL mutations instead of Meteor methods
I did some searching, and I see these lines of code
I see that if your collection is named, they use the DDP API. I’d prefer the detail of the collection name to be hidden from the higher-level concept of an entity, so I’m curious if it’s okay to use
Random.insecure.id to generate a mongo id. (Also, I’m not using Meteor methods, so from what I understand, I don’t think I have to worry about utilizing DDP.) However, the term insecure, the comments around it (“not cryptographically secure”), and the fact that it isn’t part of the public api are giving me some pause as to whether I should use that or not. (For what it’s worth, the DDP API also doesn’t seem public as it’s not listed in the Meteor docs).
In the Random docs, I do see
Random.id which might be another option, but I’m curious why Meteor uses
Random.insecure instead of
So, to sum things up, I think I have three options:
DDP.randomStream('/collection/' + name).id()
I’m leaning towards the latter mainly because it’s a public function. Does anyone think one of these is best or does it even really matter? Thank you for taking the time to read this : )