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
Specify _id with uuid #1026
Comments
in your schema, declare your _id to be either String or Buffer, then add a function default to generate it for you:
|
the fn should return the value you want to use. |
Ah, right in front of me. Sorry, i should have been able to figure this out myself. Thank you very much! |
Anytime :) On Jul 25, 2012, at 8:31 AM, porsagerreply@reply.github.com wrote:
|
in http://docs.mongodb.org/manual/core/document/#the-id-field it says:
The Mongo shell has a UUID() method that will convert a UUID string and convert it to BinData format (http://docs.mongodb.org/manual/reference/method/UUID/), but how do I do this through the Mongoose API? Is it possible to read/write the UUID from/to the model as a string but have Mongoose map to the BinData format in the DB? Or is there a convenience method for doing the conversion? Thanks for any help |
I'm not terribly familiar with UUID's - maybe the Binary type in the node driver will help? See docs |
@jaufgang the
while according to Wikipedia:
See: https://en.wikipedia.org/wiki/Universally_unique_identifier#Format It only works when you manually remove the dashes:
@porsager For using UUIDs with Mongoose, there are two modules that you can use: See also those issues: and this article for some potential problems with binary UUID representations in Mongo: |
Hi.
We want to use client generated id's in the form of UUID's in our setup, and would like to know if this is supported by Mongoose, or if there is an implementation to make it work??
It should be possible with Mongo to do this as per: http://www.mongodb.org/display/DOCS/Object+IDs#ObjectIDs-UUIDs
It seems the problem is with casting the _id when creating a new document, so maybe a plugin to mongoose to override this function could be made?
The text was updated successfully, but these errors were encountered: