Organizational Research By

Surprising Reserch Topic

mongodump query with bindata

mongodump query with bindata  using -'c#,mongodb,mongodb-csharp'

The Mongodump documentation specifies you can dump using a specific query


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.

asked Sep 28, 2015 by sujata naik
0 votes

Related Hot Questions

2 Answers

0 votes

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 \$.

answered Sep 28, 2015 by sumit_jaiswalmca
0 votes

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" } }'
answered Sep 28, 2015 by abhi