2 / 2
Apr 2024

Hi!
I am trying to export a specific subset of a collection, using mongoexport.
I am doing it in the mongoshell - more precisely in intellishell in Studio3t.
Normal queries, on “normal” datatype columns (eg string, int, etc) works fine - but the column i need to query on, is a UUID stored as binary.
I have tried following the extended json wiki to insert binary data, but it does not work.
Each time, it complains about invalid json.

The --query parameter is getting this input(just printed to console): “–query,{“ship”: {”$binary": “�_�X/��B�”
which obviously looks weird, but if i try in whatever other formats i can convert it to, it still complains.
The error message looks sort of like this: " [191 189 2… 66 239 191 189 18]’ is not valid JSON"
I guess it makes sense that binary is invalid - but i thought the notation in extended json would make that part work.

I think its probably some obvious conversion, or escape char i am missing, but i cannot for the life of me figure it out. If anyone has an idea, that would be much appreciated :slight_smile:

Hi @monkey_donkey_bonkey and welcome to the community forum!!

If I understand your concern correctly, you are trying to use mongoexport on a specific field value of type UUID.

This is what I tried on MongoDB version 6.0.5

test> db.uuid.find() [ { _id: ObjectId('662a668ee1bef521206c2bd6'), uuid: UUID('311efb2b-8565-4aa5-9a25-977e6e696342') }, { _id: ObjectId('662a669be1bef521206c2bd7'), uuid: UUID('ae9a3692-0db6-4284-be67-16d016841011') }, { _id: ObjectId('662a669fe1bef521206c2bd8'), uuid: UUID('8f4f1f9b-fe21-486e-b196-a334857b801b') }, { _id: ObjectId('662a66a0e1bef521206c2bd9'), uuid: UUID('7ec1d907-3de8-44cb-8cb7-98a0f1379cd2') }, { _id: ObjectId('662a66a1e1bef521206c2bda'), uuid: UUID('40d4ae91-3374-411b-af66-2734116cb1fe') }, { _id: ObjectId('662a66a1e1bef521206c2bdb'), uuid: UUID('aa3873ca-a6bd-41c4-a2b8-835e8951b70c') }, { _id: ObjectId('662a66a2e1bef521206c2bdc'), uuid: UUID('1580c27a-bd6e-429b-9ae7-59d46822cfe2') }, { _id: ObjectId('662a66a3e1bef521206c2bdd'), uuid: UUID('4bb99ece-1d40-43df-811e-8c306915dce9') }, { _id: ObjectId('662a66a3e1bef521206c2bde'), uuid: UUID('78e2a31a-a076-4eac-b42b-ee2cdbe01a44') } ] test> exit aasawari.sahasrabuddhe@M-C02DV42LML85 ~ % aasawari.sahasrabuddhe@M-C02DV42LML85 ~ % aasawari.sahasrabuddhe@M-C02DV42LML85 ~ % mongoexport --db test --collection uuid --fields uuid --out uuid_test.json 2024-04-25T19:50:56.244+0530 connected to: mongodb://localhost/ 2024-04-25T19:50:56.249+0530 exported 9 records aasawari.sahasrabuddhe@M-C02DV42LML85 ~ % mongoimport --db test --collection new_uuid_test --file uuid_test.json 2024-04-25T19:51:16.473+0530 connected to: mongodb://localhost/ 2024-04-25T19:51:16.572+0530 9 document(s) imported successfully. 0 document(s) failed to import. aasawari.sahasrabuddhe@M-C02DV42LML85 ~ %

I tried to generate the UUID using

db.uuid.insertOne({ "uuid": UUID()})

I was successfully able to export the UUIDs without the need of changing to hex.

Could you help me with some sample data that you are trying export ?

Regards
Aasawari