Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public static String readTask(String collectionName)
  2. {
  3. MongoClient mongoClient = new MongoClient();
  4. MongoDatabase database = mongoClient.getDatabase("exampleDatabase");
  5.  
  6. Bson lookup = new Document("$lookup",
  7. new Document("from", "Project")
  8. .append("localField", "project._id")
  9. .append("foreignField", "_id")
  10. .append("as", "something"));
  11.  
  12. List<Bson> filters = new ArrayList<>();
  13. filters.add(lookup);
  14.  
  15. AggregateIterable<Document> it = database.getCollection(collectionName).aggregate(filters);
  16. System.out.println("First Document: " + it.first().toString());
  17.  
  18. return it.toString();
  19. }
  20.  
  21. {
  22. _id = 599a62cac29d9a2684c64012,
  23. constructionRoomNumber = 1,
  24. type = 2,
  25. summary = 3,
  26. description = 4,
  27. status = Open,
  28. project = {
  29. "$ref": "Project",
  30. "$id": "5996582a0983347784fb2ff4"
  31. },
  32. something = []
  33. }
  34.  
  35. _id: ObjectId('5996582a0983347784fb2ff4')
  36. projectCode: "V1000"
  37. projectName: "Example Project"
  38. projectLocation: "1 Somewhere Street, Some City"
  39. clientName: "Whatever Client"
  40. isActive: true
  41.  
  42. _id: ObjectId('599a62cac29d9a2684c64012')
  43. constructionRoomNumber: "15"
  44. type: "Example"
  45. summary: "Summary Text"
  46. description: "Description Text"
  47. status: "Open"
  48. project: DBRef(Project, 5996582a0983347784fb2ff4, undefined)
  49.  
  50. _id: ObjectId('599a62cac29d9a2684c64012')
  51. constructionRoomNumber: "15"
  52. type: "Example"
  53. summary: "Summary Text"
  54. description: "Description Text"
  55. status: "Open"
  56. project: {
  57. _id: ObjectId('5996582a0983347784fb2ff4')
  58. projectCode: "V1000"
  59. projectName: "Example Project"
  60. projectLocation: "1 Somewhere Street, Some City"
  61. clientName: "Whatever Client"
  62. isActive: true
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement