MongoDump query with BinData

馋奶兔 提交于 2019-12-30 09:32:42

问题


The Mongodump documentation specifies you can dump using a specific query

i.e.

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

I'm storing _ids fields as BinData, is it possible to query on this?

I've tried

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

With no luck.


回答1:


This needs a lot of escaping, unfortunately. Also, you'll have to use the $binary representation instead, e.g.

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

Note that $type must be a hex string, not a number.

In linux, you'll also have to escape the $ to \$.




回答2:


You don't need to escape that much. You may just use single-quote outside of the query and double-quote inside, i.e. But beware to have the type as hex, meaning "03" and not "3"

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


来源:https://stackoverflow.com/questions/21461060/mongodump-query-with-bindata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!