Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UUID a formal Schema.Type #3208

Closed
niahmiah opened this issue Jul 28, 2015 · 9 comments · Fixed by #12268
Closed

Make UUID a formal Schema.Type #3208

niahmiah opened this issue Jul 28, 2015 · 9 comments · Fixed by #12268
Labels
new feature This change adds new functionality, like a new method or class
Milestone

Comments

@niahmiah
Copy link

Hi,

I was wondering.. why is UUID not supported as a formal Schema Type? Mongo has support for storing it as BinData(), which seems to require about 50% of the space as compared to storing them as Strings.

The mongo shell has a built in function UUID() for the conversion... It seems like this would be a nice addition to mongoose.

@vkarpov15
Copy link
Collaborator

As far as I know, the mongoose 'buffer' type is what you want for storing the BinData BSON type. http://mongoosejs.com/docs/schematypes.html

@niahmiah
Copy link
Author

niahmiah commented Aug 7, 2015

Created a PR #3242

@iamkhalidbashir
Copy link

should not be closed

@vkarpov15 vkarpov15 reopened this Jun 17, 2021
@vkarpov15 vkarpov15 added this to the 5.x Unprioritized milestone Jun 17, 2021
@vkarpov15 vkarpov15 added the new feature This change adds new functionality, like a new method or class label Jun 17, 2021
@OffensiveBias-08-145
Copy link

@vkarpov15 Any comment as to why the PR with a fix was closed?

##3242

I would love to se this feature released soon!

@vkarpov15
Copy link
Collaborator

@L14MJ4M3S0N I'm not sure why the PR was closed, the PR author closed it without any feedback.

@felipefrancisco
Copy link

+1

@OffensiveBias-08-145
Copy link

For those that are looking for a workaround and do not want to use published NPM packages, here is what I have been using.

Interface

export interface Person extends Document {
  uuid: Buffer;
...
};

Schema:

   uuid: {
      type: Schema.Types.Buffer,
      index: true,
      background: true,
      unique: true,
      default: () => new UUID(UUID.generate()).toBinary(),
    },

FindOne Example

const person = await People.findOne()
      .where({uuid: new UUID(event.pathParameters.assessmentId).toBinary()})
      .exec();

Returning a uuid as a string

      return new UUID(person.uuid).toString(),

@adarshmadrecha
Copy link

Now that #12268 is merged and released, this issue can be closed.

@hasezoey hasezoey modified the milestones: 6.x Unprioritized, 6.7 Oct 25, 2022
@hasezoey
Copy link
Collaborator

i kinda expected this to auto-close because of the keyword in #12268, but it didnt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This change adds new functionality, like a new method or class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants