如何使用Java迭代文档对象并避免错误;只能迭代java.lang.Iterable的数组或实例;? while((line=br.readLine())!=null){ Document Document=Document.parse(String.format(“{\'a\':%s}”,第行));for(Document doc:Document.get(“a”)){ docs.add(新的InsertOneModel(doc)); }

如何使用Java迭代文档对象并避免错误;只能迭代java.lang.Iterable的数组或实例;? while((line=br.readLine())!=null){ Document Document=Document.parse(String.format(“{\'a\':%s}”,第行));for(Document doc:Document.get(“a”)){ docs.add(新的InsertOneModel(doc)); },java,mongodb,Java,Mongodb,我在for循环for(Document doc:Document.get(“a”)中得到一个错误,该错误表示 只能迭代java.lang.Iterable的数组或实例 如何循环浏览文档并避免此错误?如果您只需将for循环更改为 while ((line = br.readLine()) != null) { Document document = Document.parse(String.format("{\"a\": %s}",line)); for(Document do

我在for循环
for(Document doc:Document.get(“a”)
中得到一个错误,该错误表示

只能迭代java.lang.Iterable的数组或实例


如何循环浏览文档并避免此错误?

如果您只需将for循环更改为

while ((line = br.readLine()) != null) {
         Document document = Document.parse(String.format("{\"a\": %s}",line)); for(Document doc : document.get("a")) {
               docs.add(new InsertOneModel<>(doc));
           }
for (Document doc : document.get("a").toArray()) {

}