猫鼬样本操作员不工作

问题描述 投票:0回答:1

每当我删除带有仅匹配的样本的行时,代码工作正常,但是当我像这样添加它时:

Model.aggregate(
    {$match: {}},
    {$sample: {size: 2}},
    (err, rsp)=>{
   callback(err,rsp);
});

它会抛出一个错误,说第一个参数必须是字符串或缓冲区。它只能由{$ sample:{size:2}}引起。为什么?样品不能用于猫鼬吗?

node.js database mongodb mongoose
1个回答
0
投票

试试这个 :

model.instance.aggregate([{ $match:  buildQuery(model) }]).sample(20).exec(function (err, results) {
    console.log(model.size, results.length);
});
© www.soinside.com 2019 - 2024. All rights reserved.