我不知道是否有使用的解决方案,
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); }


