【发布时间】:2018-01-18 04:02:49
【问题描述】:
我在通过 Java 使用 MongoDb 时遇到问题 我想展示我的作曲程序
DBCollection coll = db.getCollection("datatrain");
DBCursor cursor = coll.find();
Iterator<DBObject> dbo = cursor.iterator();
while (dbo.hasNext()) {
double column1 = (double) dbo.next().get("column1");
System.out.println(column1); //result show as I expected
}
System.out.println(column1); //only first document printed and local variable error
有没有什么方法可以在while之外的所有文档中获取数据?我知道 while 中的 column1 是一个列表,我想在 while 之外使用它来成为数组。我试过使用 toArray 但它总是给我错误。在程序中使用 toArray 有什么好的方法吗?
【问题讨论】:
标签: java arrays mongodb list database