to Array不是mongo数据库中的函数,mongoose,node.js
`getCartProducts: (userId) => {
return new Promise(async (resolve, reject) => {
let cart Items = await db.cart.aggregate([
{`your text`
$match: { user: user Id }//matched with the id
},
{
$lookup: {
from: "db.products",
let: { proList: '$products' },
pipeline: [
{
$match: {
$expr: {
$in: ["$_id", '$$proList']
}
}
}
],
as: 'cart Items' //converted as cart Items name
}
}
]).`to array`()
resolve(`cart Items`)
})
}
db.cart.aggregate().to Array不是一个函数,我试图删除to数组,但它显示为未定义
1条答案
按热度按时间rjee0c151#
问题是您正在对promise执行toArray(),它应该是这样的..您不需要创建自定义promise..