使用BinData进行MongoDump查询

Mongodump文档指定您可以使用特定查询进行转储

mongodump --host localhost --db mydb --collection testCollection --query "{SomeKey: 'some value'}" 

我将_ids字段存储为BinData,是否可以对此进行查询?

我试过了

 mongodump --host localhost --db mydb --collection testCollection --query "{_id: 'BinData(3,ryBRQ+Px0kGRsZofJhHgqg==)'}" 

没有运气。

遗憾的是,这需要大量的逃避。 此外,您将不得不使用$binary表示,例如

 mongodump --host localhost --db test --collection bd --query "{\"_id\" : { \"$binary\" : \"ryBRQ+Px0kGRsZofJhHgqg==\", \"$type\" : \"03\" } }" 

请注意, $type必须是hex字符串,而不是数字。

在linux中,你还必须将$转义为\$

你不需要逃避这么多。 您可以在查询之外使用单引号并在内部双引号,即但要注意类型为hex,表示“03”而不是“3”

 mongodump --host localhost --db test --collection bd --query '{"_id" : { "$binary" : "ryBRQ+Px0kGRsZofJhHgqg==", "$type" : "03" } }'