如何在猫鼬中克隆聚合对象副本

时间:2020-05-27 10:55:32

标签: node.js database mongodb mongoose aggregate

我想克隆一个聚合对象的副本来执行两种类型的查询。我的示例代码如下

const aggregation = db.users.aggregate().match(query);

// From there I want to split this into 2 clone object.
// Suppose there was a .clone function
const aggregation1 = aggregation.clone().count('total');
const aggregation2 = aggregation.clone().skip(skip).limit(limit);

Promise.all([aggregation1.exec(), aggregation2.exec()]);

我该如何实现?感谢您的帮助,谢谢。

0 个答案:

没有答案