开发者

How to specify UUID in mongo $where clause

开发者 https://www.devze.com 2023-03-13 15:03 出处:网络
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:

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号