我需要将以下查询转换为 Java 代码
使用 dbName
db.collectionName.find({},{reference:1})
我正在尝试获取键“参考”的值
我尝试了以下方法,但这似乎不是这样
Mongo dbConnection;
DB dbobject;
dbConnection = new Mongo("localhost", 27017);
dbobject = dbConnection.getDB("dbName");
DBCollection profileCollection = dbobject.getCollection("collectionName");
BasicDBObject query = new BasicDBObject();
query.put("{},{reference:1}");
DBCursor mongocursor =profileCollection.find("{}, {reference:1}");
try {
while(mongocursor.hasNext()) {
System.out.println(mongocursor.next().get("reference"));
}
} finally {
mongocursor.close();
}