What is the proper way to replace _id
type from ObjectId
to UUID
in mongoose 6
#13025
Unanswered
Freezystem
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've read a lot of post in SO or GH where people are trying to implement UUIDs properly instead of ObjectIds. But these posts are a bit outdated for most of them or incomplete. I also wanted to avoid third party librairies like mongoose-uuid2.
The official documentation is not even mentioning the official
UUID
schema type.I also have read that storing UUIDs as
Buffer
instead ofString
improve overall storage and index performance but it could be false.Also it is not clear if I should use
uuidv1
oruuidv4
generator as mongooseUUID
type mention both in its source.So for the moment I'm doing something like this:
But I get some errors, especially with the organization reference when I try to destructure a newly created user and organization isn't provided, example:
Seems like the UUID getter is missing an
undefined
ornull
test before trying to cast it or maybe I'm missing something.If I remove
organization
the error does not occur.Beta Was this translation helpful? Give feedback.
All reactions