我正在尝试让Mongo返回客户的订单列表。其中 orders 是使用$lookup
添加到 customer 文档的列表(数组)。
我主要在此工作,但我无法正确获取订单的查找集合。除了排序,它可以分开工作。
我认为我可能需要使用$unwind
,但是我发现很难知道如何将其集成到查找中以及将其放置在何处。
List<Bson> pipeline
= Arrays.asList(
new Document("$match",new Document("_id",new ObjectId(customerId))),new Document("$lookup",new Document("from","orders")
.append("localField","_id")
.append("foreignField","customer_id")
.append("as","orders")));
我确实查看了google和堆栈溢出,但找不到看起来像它解决了我所遇到问题的答案。
我想按加入客户的订单集合中的date_raised
对订单进行排序。