我不知道是否有使用的解决方案,application.properties
但是这是我的解决方案,用于从每行包含一个文档的文件中导入文档。
public static void importDocumentsFromJsonFile(File file) {
//Read each line of the json file. Each file is one observation document.
List<Document> observationDocuments = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(file.getPath()));) {
String line;
while ((line = br.readLine()) != null) {
observationDocuments.add(Document.parse(line));
}
} catch (IOException ex) {
ex.getMessage();
}
mongoTemplate.getCollection("yourCollection").insertMany(observationDocuments);
}