Sorry if this is a duplicate post. I posted and can't find it anywhere.
How can I generate Mongo objectIDs myself.
In Node.js, I'd do the following :
var ObjectID = require('mongodb').ObjectID;
var myObjectID = new ObjectID();
Kinvey provides the collectionAccess.objectId() method. Unfortunately, this only CONVERTS existing strings to objectIDs. Can y'all rewrite this method so that it generates objectIds if no string is provided?
What's the use case? Are you looking to generate ObjectIDs for attributes other than _id?
about 6 years ago
I will have a collection with documents that have subdocuments. Those subdocuments need a unique id that will be tied in a many-to-many relationship in another collection. I can create a GUID, but that is overkill size wise. The MongoDB ObjectID would work perfectly for this.
almost 6 years ago
Actually the objectID method will also generate a random objectID: