[英]TypeError: Cannot call method 'toArray' of undefined while aggregatein mongo in node.js
在 node.js 中進行聚合時出現以下錯誤。
錯誤:類型錯誤:無法調用未定義的方法“toArray”
doctorsCollection.aggregate([
{$project:{"treatments._id":1, "treatments.price":1}},
{$unwind:"$treatments"},
{$match:{"treatments._id": parseInt(treatments[i])}},
{$sort:{"treatments.price":-1}},
{$limit:1}
]).toArray(function(err, result) {
console.log(err);
});
我不知道是怎么回事。 任何幫助,將不勝感激。 謝謝!
從 node.js MongoDB 驅動程序的.aggregate
文檔中,該方法不會返回游標,除非您指定它返回游標作為選項。 默認情況下,它將返回null
因此.toArray
方法不起作用/沒有意義。
有幾種方法可以處理它,文檔提供了大量示例。 在您的情況下,您可以將{cursor: {batchSize: 1}}
為.aggregate
的第二個參數,它會起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.