At the moment I am generating unique UUID's and save them as a string in MongoDB. Is there a way to store these UUID's as ObjectID in MongoDB.
The problem is that User.findOne based on _id doesn't work because UUID is a string and not a ObjectID
At the moment I am generating unique UUID's and save them as a string in MongoDB. Is there a way to store these UUID's as ObjectID in MongoDB.
The problem is that User.findOne based on _id doesn't work because UUID is a string and not a ObjectID
you don't have to generate the uuids of entities mongoose do it for you, for example if you use the create() method without passing the _id it will generate it.
it's sure better to hand-generate it.
and its by default.
So basically store them as _id: UUID("5fe6075a-8157-4dfc-8aab-3316ea9cbf17")
format instead of string. Then it should work as expected with findOne(). Also you may refer to this answer.