2

I have an object that was stored via mongo-java-driver. Object uses java.util.UUID for its _id field. Following is presentation of object via mongo shell:

> db.b.find()
{ "_id" : BinData(3,"zUOYY2AE8WZqigtb/Tqztw==") }

I have a requirement to process searching via $where clause. I use following code to do it:

Mongo m = new Mongo();
DBCollection coll = m.getDB("a").getCollection("b");
coll.save(new BasicDBObject("_id", UUID.randomUUID()));
// ??? - don't know what should be specified
DBObject query = new BasicDBObject("$where", "this[\"_id\"] == " + ???);
coll.find(query).count()

The question is what should I specify instead of ??? to make it work?

Thanks for any help.

Parvin Gasimzade
  • 25,180
  • 8
  • 56
  • 83
Raman
  • 887
  • 4
  • 12
  • 28

1 Answers1

0

My invesigation shown that only one way to do it is rewriting a query in object based way (I mean migration of $where clause part to BasicDBObject based query). In such case mongo-java-driver supports java.util.UUID without any additional effort.

Raman
  • 887
  • 4
  • 12
  • 28