Insert MongoDb _id field as UUID object

Hello,

I'm trying to build simple migration tool for importing (subset of) documents from one MongoDb (sourceDb) to another MongoDb (targetDb). In the sourceDb, we have documents with _id field saved as UUID() objects. When I load (find) the documents in Retool query, the _id UUIDs are returned as plain strings, but I would like to insert those documents into targetDb as UUID() objects.

I tried to transform loaded string UUIDs into MongoDB extended JSON format UUID objects and then insert documents into targetDb, like this:

{ "$binary":
   {
      "base64": "{uuid string converted to base64 with js btoa function}",
      "subType": "04"
   }
}

But I got this error message when inserting: "Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."

I would appreciate any help. Is it even possible to save fields as UUID objects from Retool?

Thank you.

I found solution for my problem here: specifications/extended-json.rst at master · mongodb/specifications · GitHub

TLDR: uuid can be inserted in this format: {"$uuid": }