Guest User

Untitled

a guest
Nov 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. @Procedure
  2. @Description("apoc.mongodb.find(host-or-port,db-or-null,collection-or-null,query-or-null,projection-or-null,sort-or-null,[compatibleValues=true|false]) yield value - perform a find,project,sort operation on mongodb collection")
  3. public 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) {
  4. return getMongoColl(hostOrKey, db, collection, compatibleValues).find(query, project, sort).map(MapResult::new);
  5. }
  6.  
  7. interface Coll extends Closeable {
  8.  
  9. ...
  10.  
  11. Stream<Map<String, Object>> find(Map<String, Object> query, Map<String, Object> project, Map<String, Object> sort, Map<String, Object> pagination);
  12.  
  13. @Override
  14. public Stream<Map<String, Object>> find(Map<String, Object> query, Map<String, Object> project, Map<String, Object> sort, Map<String, Object> pagination) {
  15. FindIterable<Document> documents = query == null ? collection.find() : collection.find(new Document(query));
  16. if (project != null) documents = documents.projection(new Document(project));
  17. if (sort != null) documents = documents.sort(new Document(sort));
  18. if (pagination != null) {
  19. Object skip = pagination.get("skip");
  20. Object limit = pagination.get("limit");
  21. if (skip != null) documents = documents.skip(Integer.parseInt(String.valueOf(skip)));
  22. if (limit != null) documents = documents.limit(Integer.parseInt(String.valueOf(limit)));
  23. }
  24. return asStream(documents);
  25. }
Add Comment
Please, Sign In to add comment