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

feat(NODE-1046): natively support UUID (de)serialization #465

Closed

Conversation

typesafe
Copy link

@typesafe typesafe commented Oct 17, 2021

This introduces a global DefaultDeserializeOptions.convertUUIDs and also extends the existing DeserializeOptions with a new convertUUIDs flag. Setting the flag will simply deserialize Binary values with subtype SUBTYPE_UUID as actual UUID instances.

It's great that we have the UUID type, but I really want to avoid having to tediously map these values/fields back-and-fort. This is bound to end up in subtle bugs sooner or later. As a bonus, UUID also features a toJSON eliminating mapping altogether when returning data as JSON.

In case you're using Typescript, you can define fields as UUID and it "just works":

export interface SomeDocument {
...
externalId: UUID;
...
}

I tried to get some feedback via https://github.com/mongodb/js-bson/issues/234, but thought I might as well open a PR 🙂.

@typesafe
Copy link
Author

Any thoughts on this?

@dariakp
Copy link
Contributor

dariakp commented Oct 25, 2021

@typesafe Hi there, apologies for the delayed response, the team has been swamped with end of quarter work. At this point, the feature is not scheduled to be picked up by the team, however, given the renewed interest, we are going to revisit it later this week and check whether it aligns with our existing roadmap for this library. We'll have an update for you early next week at the latest.

At a glance, your implementation appears to present a potentially viable solution (and we certainly appreciate the added tests!), however, we need to do our due diligence to ensure that a) it does indeed meet the requirements around this feature from a product perspective, b) it does not conflict with any current plans for related features, and c) that we will be able to dedicate the necessary resources as a team to deliver and maintain this feature in the context of our other priorities. Thank you for your patience!

@typesafe
Copy link
Author

Hey @dariakp, thanks for the update! I of course totally understand the due diligence 👍 👌 .

@dariakp
Copy link
Contributor

dariakp commented Oct 28, 2021

@typesafe After a discussion with the team, we think that we'd like to take on the UUID feature improvement as a concerted effort in about 1-2 months time. There is related work that needs to be done to make our implementation fully spec compliant, and, at this point, I'm not sure that we'll be able to take your specific approach to the convertUUIDs option - we'll have to go through the technical design process for the feature set as a whole, although @nbbeeken can provide additional context on our current considerations. Thank you again for providing your suggestion. We'll keep you updated on the direction once we schedule the work.

@typesafe
Copy link
Author

Thanks for the update. I was hoping for sooner, but I understand 🙂 .

@nbbeeken
Copy link
Contributor

We appreciate your understanding @typesafe we are considering this feature carefully, its adding a new paradigm where on driver side we'll likely need to keep a global setting (as in across all MongoClient instances) for convertUUIDs along side a setting for uuidRepresentation. In the meantime there is a toBSON method that can be used to customize the way objects get serialized. One could use that to add automatic UUID support.

The purpose of the spec rule to make converting UUIDs explicit is to avoid bugs that are worse than mistakenly forgetting to do the explicit conversion. At least forgetting the explicit call will crash. However, because of those legacy language specific UUID formats if users don't correctly deserialize and serialize the UUID as the correct representation it was stored as in MongoDB, the bytes of the UUID will be reordered unexpectedly and silently, making a UUID completely different on round trip.

@nbbeeken
Copy link
Contributor

Just a suggestion, obviously with its own upsides/downsides/caveats, using a combination of the cursor's map function and the toBSON method one could implement the automatic conversion at the app layer.

const docs = col.find().map(d => /* convert Binary(s) to UUID */)
const res = col.insertOne({ toBSON() { /* convert UUIDs to Binary */ } })

@typesafe
Copy link
Author

typesafe commented Jan 12, 2022

Hey @dariakp & @nbbeeken, I was wondering if there's an update on this 😇

@dariakp
Copy link
Contributor

dariakp commented Jan 18, 2022

@typesafe Unfortunately due to higher priority issues we have not yet had a chance to schedule this, and I don't know whether we'll be able to in the upcoming quarter. I did send the ticket into the triage queue to see if we can get something more concrete in terms of a date.

@bajanam bajanam added the tracked-in-jira There is a ticket in Mongo's Jira instance tracking this issue/PR label Mar 7, 2022
@nbbeeken
Copy link
Contributor

Hi @typesafe, thanks again for your assistance with this feature, we've fleshed out a design to make sure we hit all the marks here. EJSON and BSON will both support the UUID instance, along with an option to control the new changes. You can look forward to the feature landing soon, and you can view the project on our JIRA here
ref: #508

@nbbeeken nbbeeken closed this Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira There is a ticket in Mongo's Jira instance tracking this issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants