Answer the question
In order to leave comments, you need to log in
Can't find error in JAVA code?
There is a newclicklogs.json file. I'm trying to get it into my MOngoDB. I can not understand what is wrong. Help PLEASE!
public static void main(String[] args)throws IOException{
mongo mongoDemo = new mongo();
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
MongoDatabase database = mongoClient.getDatabase("KAMBUL");// initialize to the path of the file to read from
MongoCollection<Document> collection = database.getCollection("asda");
String inputFilename="C:\\data/newclicklogs.json"; // initialize to the path of the file to read from
// initialize to the collection to which you want to write
BufferedReader reader = new BufferedReader(new FileReader(inputFilename));
List<InsertOneModel<Document>> docs = new ArrayList<>();
try {
String json;
while ((json = reader.readLine()) != null) {
Document document = Document.parse(String.format("{\"a\": %s}", json));
for(Document doc:document.get("a")) // РУГАЕТСЯ ЗДЕСЬ
{docs.add(new InsertOneModel<>(doc));}
}
} finally {
reader.close();
}
}
}
Answer the question
In order to leave comments, you need to log in
It is written in black and white that only arrays and Iterable can be iterated. What does get return? That's right, Object.
https://api.mongodb.com/java/3.2/org/bson/Document...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question