I am trying to query a large collection by the _id field which uses BinData.
Some of these ids use BinData of type 4:
"_id" : BinData(4,"CNDF66qIlCY92q1vFAAAAQ==")
While some use BinData of type 3:
"_id" : BinData(3,"CNDF66qJ29g92q1vFAAAEw==")
I need to find all of the _id fields that have BinData.type = 3 and was wondering if anyone has had luck querying like this in the MongoDB shell.
Any help would be greatly appreciated!
You can do this with a $where
style query as the BinData
object has a .subtype()
method that returns that "type":
db.collection.find(function(){ return this._id.subtype() == 3 })
Note that the "type" 3 BinData is by default what would be generated by the new UUID helper available to the shell from MongoDB 2.6:
UUID("0123456789abcdeffedcba9876543210")
BinData(3,"ASNFZ4mrze/+3LqYdlQyEA==")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With