-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
How to use aggregate match with UUID type? #12893
Comments
Maybe this might help |
Also, mongoose does not have any UUID type in mongoose.Types as you can see here: https://github.com/Automattic/mongoose/blob/master/lib/types/index.js But, as you can see in this file there is a constructor called SchemaUUID() in the UUID Schema Type, so try to use that once and see what's the result |
I tried with this as suggested:
It didn't crash, but it returns 0 results despite me running the equivalent on the server with MongoDB's UUID() function and it returning the document as expected. Edit: I also tried accessing SchemaUUID() since it seems to be different from mongoose.Schema.Types.UUID(), but I can't access it because it's not exported (plus |
It looks like the native mongodb driver doesn't export the import { UUID } from "bson";
...
let my = await My.aggregate().match({_id: new UUID("1e984535-98ad-446b-84cc-bd8f59290eb8")}).exec(); |
Thanks @guilhermedalleprane, that's solved my issue. I'll leave this up to the maintainers whether to close or not. |
Since MongoDB's latest driver (5.x) exports the UUID class now, I made feature request #13103 to add UUIDs as a type in Mongoose. The best way to get the UUID class with Mongoose 7 is now |
Prerequisites
Mongoose version
6.8.3
Node.js version
16.17.1
MongoDB version
6.0.3
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Fedora 37
Issue
I understand that mongoose does not automatically cast values in aggregate pipelines, and I've been trying to find how to do this for UUIDs but have been unsuccessful.
My reduced schema:
What I'm (failing) to do:
The above fails with
TypeError: mongoose.Types.UUID is not a constructor
, but this seems to be the solution for ObjectIds (obviously with UUID replaced to ObjectId). How can I aggregate match with UUIDs in mongoose?The text was updated successfully, but these errors were encountered: