8

I have a document in MongoDB like

{ "_id" : ObjectId("51723a2f2b9b90e9eb190c45"), "d" : BinData(0,"c9f0f895fb98ab9159f51fd0297e236d") }

The field "d" is indexed, but how can I find by its value in mongo shell?

e.g.

db.test.find( {"d": BinData(0,"c9f0f895fb98ab9159f51fd0297e236d") } )

Not working, any idea?

Howard
  • 19,215
  • 35
  • 112
  • 184

1 Answers1

6

Bindata is the base64 representation of a binary string.Must be instantiated.

db.test.find( {"d": new BinData(0,"c9f0f895fb98ab9159f51fd0297e236d") } )
user3796198
  • 61
  • 1
  • 3
  • On Mongo `4.0.18`, I had to use `db.test.find( {"_id": new BinData(0,"c9f0f895fb98ab9159f51fd0297e236d") } )` – Ryan Gates Sep 24 '20 at 14:38