12

I am trying to query a binary field in mongo db. The data looks like this:

{"_id":"WE8fSixi8EuWnUiThhZdlw=="}

enter image description here

I've tried a lot of things for example:

{ '_id': new Binary( 'WE8fSixi8EuWnUiThhZdlw==', Binary.SUBTYPE_DEFAULT) }
{ '_id': Binary( 'WE8fSixi8EuWnUiThhZdlw==', 0) }

etc

Nothing seems to be working, have exhausted google and the mongo documentation, any helper would be amazing.

1 Answer 1

15

UPDATE:

Now you should be able to query UUID and BinData from MongoDB Compass v1.20+ (COMPASS-1083). For example: {"field": BinData(0, "valid_base64")}.

PREVIOUS:

I see that you're using MongoDB Compass to query the field. Unfortunately, the current version of MongoDB Compass (v1.16.x) does not support querying binary data.

You can utilise mongo shell to query the data instead. For example:

db.collection.find({'_id':BinData(0, "WE8fSixi8EuWnUiThhZdlw==")});

Please note that the field name _id is reserved for use as a primary key; its value must be unique in the collection, and is immutable. Depending on the value of the binary that you're storing into _id, I would suggest to store the binary in another field and keep the value of _id to contain ObjectId.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I managed to get it working by changing too to Robo 3T. This allowed me to query with binary. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.