Как объединить три коллекции, используя в Mongo с Java?
Вот мой код (или лучше без datasetTemp),
, но он возвращает пустой результат, как это исправить?
Morphia morphia = new Morphia();
morphia.mapPackage("com.x.core.order.report");
MongoClient bean = new AnnotationConfigApplicationContext(SpringMongoConfig.class).getBean(MongoClient.class);
Datastore datastore = morphia.createDatastore(bean, "x");
datastore.ensureIndexes();
User user = new User();
user.setEmail("eeeeeeee");
Order order = new Order();
order.setComment("cccccccc");
datastore.save(user);
order.setProducerAssigneeId(user.getId());
datastore.save(order);
MongoDatabase db = bean.getDatabase("x");
MongoCollection<Document> users = db.getCollection("orders");
BasicDBObject match = new BasicDBObject("$match",
new BasicDBObject("_id", order.getId())
);
BasicDBObject lookupFields = new BasicDBObject("from", "users");
lookupFields.put("localField", "producerAssigneeId");
lookupFields.put("foreignField", "_id");
lookupFields.put("as", "producerAssignee");
BasicDBObject lookup = new BasicDBObject("$lookup", lookupFields);
BasicDBObject out = new BasicDBObject("$out", "datasetTemp");
List<BasicDBObject> pipeline = Arrays.asList(match, lookup, out);
AggregateIterable<Document> resultAgg = users.aggregate(pipeline);
MongoCollection<Document> tmp = db.getCollection("datasetTemp");
tmp.find().first();//...