mongodb 点符号查找 [英] mongodb dot notation find
本文介绍了mongodb 点符号查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如可以通过 mongo shell 查找带有点符号的记录:
finding a record with dot notation is possible via mongo shell for example:
db.events.find({'events.eid':307215649389788})
我试图用 java 驱动程序实现同样的目标,问题是:
I'm trying to achieve the same thing with java drivers, problem is:
- db.getCollection(collectionName).find(query) - 期望查询作为 DBObject.
- 在创建以events.eid"为键的 DBObject 时,构造函数添加了",因此我得到以下结果:‘events.eid’"作为键不起作用(也在 shell 中).
我怎样才能克服这个问题?
how can I overcome this?
推荐答案
不太确定您在尝试什么,但这有效:
Not quite sure what you're trying, but this works:
DBCursor cursor = coll.find(new BasicDBObject("events.eid", 307215649389788));
您需要对 Java 字符串使用双引号 ("
),因此如果您使用单引号,那是您的问题.
You need to use double quotes ("
) with Java strings so if you're using single quotes that's your problem.
这篇关于mongodb 点符号查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文