Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String readTask(String collectionName)
- {
- MongoClient mongoClient = new MongoClient();
- MongoDatabase database = mongoClient.getDatabase("exampleDatabase");
- Bson lookup = new Document("$lookup",
- new Document("from", "Project")
- .append("localField", "project._id")
- .append("foreignField", "_id")
- .append("as", "something"));
- List<Bson> filters = new ArrayList<>();
- filters.add(lookup);
- AggregateIterable<Document> it = database.getCollection(collectionName).aggregate(filters);
- System.out.println("First Document: " + it.first().toString());
- return it.toString();
- }
- {
- _id = 599a62cac29d9a2684c64012,
- constructionRoomNumber = 1,
- type = 2,
- summary = 3,
- description = 4,
- status = Open,
- project = {
- "$ref": "Project",
- "$id": "5996582a0983347784fb2ff4"
- },
- something = []
- }
- _id: ObjectId('5996582a0983347784fb2ff4')
- projectCode: "V1000"
- projectName: "Example Project"
- projectLocation: "1 Somewhere Street, Some City"
- clientName: "Whatever Client"
- isActive: true
- _id: ObjectId('599a62cac29d9a2684c64012')
- constructionRoomNumber: "15"
- type: "Example"
- summary: "Summary Text"
- description: "Description Text"
- status: "Open"
- project: DBRef(Project, 5996582a0983347784fb2ff4, undefined)
- _id: ObjectId('599a62cac29d9a2684c64012')
- constructionRoomNumber: "15"
- type: "Example"
- summary: "Summary Text"
- description: "Description Text"
- status: "Open"
- project: {
- _id: ObjectId('5996582a0983347784fb2ff4')
- projectCode: "V1000"
- projectName: "Example Project"
- projectLocation: "1 Somewhere Street, Some City"
- clientName: "Whatever Client"
- isActive: true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement