Skip to content

Conversation

@Anemy
Copy link
Member

@Anemy Anemy commented Nov 13, 2025

MONGOSH-2486

Description

Adds LegacyJavaUUID, LegacyCSharpUUID, and LegacyPythonUUID helpers to the query-parser, shell-bson-parser, and mongodb-constants. These are ways for folks to pass a UUID string in the canonical form 00112233-4455-6677-8899-aabbccddeeff and have it encoded how the various legacy implementations did it. See the short history of UUIDs for more info.

In the next ticket, COMPASS-9690, we'll be adding this to Compass and providing a setting to customize how we're rendering the Binary subtype 3. We won't be adding that in mongosh, we'll keep showing the formatBinary.createFromBase64('Y7mFuOjdS9qQh+RALxo/9g==', 3).

https://www.mongodb.com/docs/languages/python/pymongo-driver/current/data-formats/uuid/#a-short-history-of-mongodb-uuids
Brief: UUID Support in Compass & Mongosh

LegacyJavaUUID: function (u: any) {
if (u === undefined) {
// Generate a new UUID and format it.
u = new bson.UUID().toHexString();
Copy link
Member Author

@Anemy Anemy Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatting with @nbbeeken I think we were thinking of throwing an error here instead. This is when someone writes new LegacyJavaUUID() without a string in the quotes. Currently UUID creates a new UUID so I had initially written it to also generate a new UUID (of subtype 3).
Any other opinions on if it we should throw an error or allow it? I'll add an error throw otherwise. I'll ask Betsy on it too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I think this is meaningful to have, since the "naïve" solution of replacing it with new UUID() won't necessarily generate valid legacy UUIDs

Copy link
Collaborator

@nbbeeken nbbeeken Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new UUID() won't necessarily generate valid legacy UUIDs

A little confused, yes new UUID will never make a legacy UUID. I'm suggesting that if the creation of new random UUIDs is desirable we have that mechanism in the UUID class but not in these helpers. Since this effort is intended to assist with viewing existing legacy uuids and querying them I think most of the time folks are going to have a UUID string on hand to construct one of these legacy forms.

LegacyJavaUUID(UUID());

I don't feel uber strongly about this, totally fine to keep the creation support directly in the ctor. Just sharing the perspective I had on greatly discouraging this use

snippet: "LegacyPythonUUID('${1:uuid}')",
},
{
name: 'UUID',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously UUID didn't show up in Compass' autocomplete. I'm thinking it was just missing. This will make it start showing up:

Image

value: 'LegacyJavaUUID',
label: 'LegacyJavaUUID',
score: 1,
meta: 'bson-legacy-uuid',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meta here will make it into Compass' autocompleter:

Image

@Anemy Anemy requested a review from nbbeeken November 13, 2025 23:32
LegacyJavaUUID: function (u: any) {
if (u === undefined) {
// Generate a new UUID and format it.
u = new bson.UUID().toHexString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I think this is meaningful to have, since the "naïve" solution of replacing it with new UUID() won't necessarily generate valid legacy UUIDs

String.prototype.substring.call(hex, 14, 16) +
String.prototype.substring.call(hex, 12, 14);
const d = String.prototype.substring.call(hex, 16, 32);
hex = a + b + c + d;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really care a lot, so feel free to just resolve this, but working with the binary buffers might be a bit clearer/easier

@addaleax
Copy link
Collaborator

Oh, also – this is tagged for MONGOSH-2486 but we should be careful not to close this ticket when it's merged since mongosh still has its own shell-bson package that will need to be updated

Copy link
Collaborator

@nbbeeken nbbeeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh forgot to submit approve, I leave the no arg generate / not generate choice up to yall

@Anemy
Copy link
Member Author

Anemy commented Nov 20, 2025

Merging with the no arg generate in.

@Anemy Anemy merged commit a09536c into main Nov 20, 2025
33 checks passed
@Anemy Anemy deleted the MONGOSH-2486-add-shell-helpers-for-legacy-uuid branch November 20, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants