MongoDB { @Deprecated @Procedure @Description("apoc.mongodb.get(host-or-key,db,collection,query,[compatibleValues=false|true],skip-or-null,limit-or-null,[extractReferences=false|true],[objectIdAsMap=true|false]) yield value - perform a find operation on mongodb collection") public Stream<MapResult> get(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("query") Map<String, Object> query, @Name(value = "compatibleValues", defaultValue = "false") boolean compatibleValues, @Name(value = "skip", defaultValue = "0") Long skip, @Name(value = "limit", defaultValue = "0") Long limit, @Name(value = "extractReferences", defaultValue = "false") boolean extractReferences, @Name(value = "objectIdAsMap", defaultValue = "true") boolean objectIdAsMap) { return executeMongoQuery(hostOrKey, db, collection, compatibleValues, extractReferences, objectIdAsMap, coll -> coll.all(query, skip, limit).map(MapResult::new), e -> log.error("apoc.mongodb.get - hostOrKey = [" + hostOrKey + "], db = [" + db + "], collection = [" + collection + "], query = [" + query + "], compatibleValues = [" + compatibleValues + "], skip = [" + skip + "], limit = [" + limit + "]", e)); }  @Deprecated @Procedure @Description("apoc.mongodb.get(host-or-key,db,collection,query,[compatibleValues=false|true],skip-or-null,limit-or-null,[extractReferences=false|true],[objectIdAsMap=true|false]) yield value - perform a find operation on mongodb collection") Stream<MapResult> get(@Name("host") String hostOrKey,
                                 @Name("db") String db,
                                 @Name("collection") String collection,
                                 @Name("query") Map<String, Object> query,
                                 @Name(value = "compatibleValues", defaultValue = "false") boolean compatibleValues,
                                 @Name(value = "skip", defaultValue = "0") Long skip,
                                 @Name(value = "limit", defaultValue = "0") Long limit,
                                 @Name(value = "extractReferences", defaultValue = "false") boolean extractReferences,
                                 @Name(value = "objectIdAsMap", defaultValue = "true") boolean objectIdAsMap); @Deprecated @Procedure @Description("apoc.mongodb.count(host-or-key,db,collection,query) yield value - perform a find operation on mongodb collection") Stream<LongResult> count(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("query") Map<String, Object> query); @Deprecated @Procedure @Description("apoc.mongodb.first(host-or-key,db,collection,query,[compatibleValues=false|true],[extractReferences=false|true],[objectIdAsMap=true|false]) yield value - perform a first operation on mongodb collection") Stream<MapResult> first(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("query") Map<String, Object> query, @Name(value = "compatibleValues", defaultValue = "true") boolean compatibleValues,
                                   @Name(value = "extractReferences", defaultValue = "false") boolean extractReferences,
                                   @Name(value = "objectIdAsMap", defaultValue = "true") boolean objectIdAsMap); @Deprecated @Procedure @Description("apoc.mongodb.find(host-or-key,db,collection,query,projection,sort,[compatibleValues=false|true],skip-or-null,limit-or-null,[extractReferences=false|true],[objectIdAsMap=true|false]) yield value - perform a find,project,sort operation on mongodb collection") Stream<MapResult> find(@Name("host") String hostOrKey,
                                  @Name("db") String db,
                                  @Name("collection") String collection,
                                  @Name("query") Map<String, Object> query,
                                  @Name("project") Map<String, Object> project,
                                  @Name("sort") Map<String, Object> sort,
                                  @Name(value = "compatibleValues", defaultValue = "false") boolean compatibleValues,
                                  @Name(value = "skip", defaultValue = "0") Long skip,
                                  @Name(value = "limit", defaultValue = "0") Long limit,
                                  @Name(value = "extractReferences", defaultValue = "false") boolean extractReferences,
                                  @Name(value = "objectIdAsMap", defaultValue = "true") boolean objectIdAsMap); @Deprecated @Procedure @Description("apoc.mongodb.insert(host-or-key,db,collection,documents) - inserts the given documents into the mongodb collection") void insert(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("documents") List<Map<String, Object>> documents); @Deprecated @Procedure @Description("apoc.mongodb.delete(host-or-key,db,collection,query) - delete the given documents from the mongodb collection and returns the number of affected documents") Stream<LongResult> delete(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("query") Map<String, Object> query); @Deprecated @Procedure @Description("apoc.mongodb.update(host-or-key,db,collection,query,update) - updates the given documents from the mongodb collection and returns the number of affected documents") Stream<LongResult> update(@Name("host") String hostOrKey, @Name("db") String db, @Name("collection") String collection, @Name("query") Map<String, Object> query, @Name("update") Map<String, Object> update); @Context
    public Log log; }
@Test public void testGet() { TestUtil.testResult(db, "CALL apoc.mongodb.get($host,$db,$collection,null)", params, res -> assertResult(res)); }
@Test public void testCountAll() throws Exception { TestUtil.testCall(db, "CALL apoc.mongodb.count($host,$db,$collection,null)", params, r -> { assertEquals(NUM_OF_RECORDS, r.get("value")); }); }
@Test public void shouldInsertDataIntoNeo4jWithFromDocument() throws Exception { Date date = DateUtils.parseDate("11-10-1935", "dd-MM-yyyy"); TestUtil.testResult(db, "CALL apoc.mongodb.first($host, $db, $collection, $filter, $compatibleValues, $extractReferences) YIELD value " + "CALL apoc.graph.fromDocument(value, $fromDocConfig) YIELD graph AS g1 " + "RETURN g1", map("host", HOST, "db", "test", "collection", "person", "filter", Collections.emptyMap(), "compatibleValues", true, "extractReferences", true, "fromDocConfig", map("write", true, "skipValidation", true, "mappings", map("$", "Person:Customer{!name,bought,coordinates,born}", "$.bought", "Product{!name,price,tags}"))), r -> { Map<String, Object> map = r.next(); Map graph = (Map) map.get("g1"); assertEquals("Graph", graph.get("name")); Collection<Node> nodes = (Collection<Node>) graph.get("nodes"); Map<String, List<Node>> nodeMap = nodes.stream() .collect(Collectors.groupingBy(e -> e.getLabels().iterator().next().name())); List<Node> persons = nodeMap.get("Person"); assertEquals(1, persons.size()); List<Node> products = nodeMap.get("Product"); assertEquals(2, products.size()); Node person = persons.get(0); Map<String, Object> personMap = map("name", "Andrea Santurbano", "born", LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())); assertEquals(personMap, person.getProperties("name", "born")); assertTrue(Arrays.equals(new double[] {12.345, 67.890}, (double[]) person.getProperty("coordinates"))); assertEquals(Arrays.asList(Label.label("Person"), Label.label("Customer")), person.getLabels()); Node product1 = products.get(0); Map<String, Object> product1Map = map("name", "My Awesome Product", "price", 800L); assertEquals(product1Map, product1.getProperties("name", "price")); assertArrayEquals(new String[]{"Tech", "Mobile", "Phone", "iOS"}, (String[]) product1.getProperty("tags")); assertEquals(Arrays.asList(Label.label("Product")), product1.getLabels()); Node product2 = products.get(1); Map<String, Object> product2Map = map("name", "My Awesome Product 2", "price", 1200L); assertEquals(product2Map, product2.getProperties("name", "price")); assertArrayEquals(new String[]{"Tech", "Mobile", "Phone", "Android"}, (String[]) product2.getProperty("tags")); assertEquals(Arrays.asList(Label.label("Product")), product2.getLabels()); Collection<Relationship> rels = (Collection<Relationship>) graph.get("relationships"); assertEquals(2, rels.size()); Iterator<Relationship> relIt = rels.iterator(); Relationship rel1 = relIt.next(); assertEquals(RelationshipType.withName("BOUGHT"), rel1.getType()); assertEquals(person, rel1.getStartNode()); assertEquals(product1, rel1.getEndNode()); Relationship rel2 = relIt.next(); assertEquals(RelationshipType.withName("BOUGHT"), rel2.getType()); assertEquals(person, rel2.getStartNode()); assertEquals(product2, rel2.getEndNode()); }); }