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循环for (Document doc : document.get("a"))
中遇到错误,
只能在数组或Java.lang.iterable
的实例上迭代
如何循环浏览文档并避免此错误?
如果您简单地将for循环更改为
for (Document doc : document.get("a").toArray()) {
}