0

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 :-/

4

1 回答 1

3

好的,当使用类型作为十六进制值(意思是 03 而不是 3)时,它终于可以工作了,并且不需要转义:

mongoexport --db test --collection collec --query '{"uuid": { "$binary": "zaHKuGOpQqOxf3tkCofZjw==", "$type": "03"}
于 2014-01-31T13:19:06.227 回答