How to use mongoexport with query containing binary data (like UUID) [duplicate]

StackOverflow https://stackoverflow.com/questions/21479569

  •  05-10-2022
  •  | 
  •  

Pergunta

I just had an annoying problem. I wanted to use mongoexport, with a query containing binary data and couldn't bring it to work.

You may reproduce it by creating a collection which contains a UUID Field.

The following should work but doesn't (returning 'FailedToParse: Argument of $type in $bindata object must be a hex string representation of a single byte'):

mongoexport --db test --collection collec --query '{"uuid": { "$binary": "zaHKuGOpQqOxf3tkCofZjw==", "$type": "3"}}'

I also tried this one, using the shell BSON type, it doesn't work either (returning 'FailedToParse: "new" keyword not followed by Date constructor'):

mongoexport --db test --collection collec --query '{"uuid": { new BinData(3, "zaHKuGOpQqOxf3tkCofZjw==")}'

And neither does this one (inspired from mongoexport doc 2.4, returning 'FailedToParse: Expecting quoted string'):

mongoexport --db test --collection collec --query "{uuid: { \$binary: 'zaHKuGOpQqOxf3tkCofZjw==', \$type: 3}}"

Any hint ? Could it be a bug ? My version of mongo is 2.4.6. I ended up querying and printing from Django and mongoengine :-/

Foi útil?

Solução

OK, it works finally, when using the type as a hex value (meaning 03 instead of 3), and no escaping required:

mongoexport --db test --collection collec --query '{"uuid": { "$binary": "zaHKuGOpQqOxf3tkCofZjw==", "$type": "03"}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top