Advertisement
dr1v3r3k

mongo insertMany

Sep 20th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. private static void hashMap_Example(DBCollection collection) throws IOException {
  2.          Map<String, Document> documentMap = new HashMap<>();
  3.         Reader reader = Files.newBufferedReader(Paths.get("C:\\Users\\Pepe\\Desktop\\kopiagrafiku.csv"));
  4.         CSVParser csvParser = new CSVParser(reader, CSVFormat.newFormat(';'));
  5.         Document document = new Document("date", "15.09.2019");
  6.  
  7.         document.append("rodzaj_rozkladu", "powszedni");
  8.         for (CSVRecord record : csvParser) {
  9.             Map<String, Object> documentMapDetail = new HashMap<String, Object>();
  10.             document.append("workNumber", record.get(0));
  11.             if (record.get(0).isEmpty())
  12.                 continue;
  13.             document.append("busLine", record.get(1));
  14.             document.append("startTime", record.get(2));
  15.             document.append("endTime", record.get(3));
  16.             documentMap.put("grafik_dzienny", document);
  17.             collection.insert((List<? extends DBObject>) documentMap);
  18.         }
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement