Thanks to visit codestin.com
Credit goes to github.com

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

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

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.

3 participants