Binary Data Request - MongoDB

I am using the Java driver for MongoDB (2.14) in my application.
I have the following documents:

{ "_id" : ObjectId("56fb9798e2445ade35effa89"), "b" : BinData(3,"abcdefgh") }
{ "_id" : ObjectId("56fba265e2445ade35effa8c"), "b" : 1 }

I need to get all documents where "b"is binary data using Java. To achieve my goal, I use the following query:

DBObject query = new BasicDBObject(b, new BasicDBObject("$type",5));
DBObject projKeys = new BasicDBObject();
projKeys.put("_id", 0);
projKeys.put(b, 1);

DBCursor cursor = coll.find(query,projKeys);

But when I start iterating over cursor, I get an exception:

java.lang.IllegalArgumentException: invalid data size subtype 3 len: 6! = 16

When I try to make the same request using the mongo shell, that is:

db.coll.find({b:{"$type":5}}, {_id:0,b:1})

I have no mistakes.

+4
source share
1 answer

3 UUID, "" 16 (32 ). , , Java-.

MongoDB "" , , . MongoDB " ", BSON Type 5 .

, :

{ "b": BinData(3,"ASNFZ4mrze/+3LqYdlQyEA==") }

, , 0:

{ "b": BinDta(0,"abcdefgh") }

Java Binary.

, , "". , .

+3
source

All Articles