mongodb :: 由 :: 引起 :: 在 $convert 中尝试将 NaN 值转换为整数类型,没有 onError 值

问题描述 投票:0回答:1
 {
                    $match: { user: mongodb.ObjectId(userId) }
                },
                {
                    $unwind: '$products'
                },
                {
                    $project: {
                        item: '$products.item',
                        quantity: '$products.quantity'
                    }
                },
                {
                    $lookup: {
                        from: collection.PRODUCT_COLLECTION,
                        localField: 'item',
                        foreignField: '_id',
                        as: 'product'
                    }
                },
                {
                    $project: {
                        item: 1, quantity: 1, product: { $arrayElemAt: ['$product', 0] }
                    }
                },
                {
                    $group: {
                        _id: null,
                        total: { $sum: { $multiply: [{ $toInt: '$quantity' }, { $toInt: '$product.Price' }] } }
                    }
                }

            ])

但它说 UnhandledPromiseRejectionWarning: MongoServerError: PlanExecutor error during aggregation :: caused by :: Attempt to convert NaN value to integer type in $convert with no onError value

javascript arrays mongodb mongodb-query aggregate
1个回答
0
投票

我建议从数据库中删除特定文档。

© www.soinside.com 2019 - 2024. All rights reserved.