首页 > 解决方案 > 如何在 mongdb 中不返回查找结果

问题描述

我想通过使用查找功能检查该帐户是否在任何订单中使用来返回帐户。但我不想返回查找结果。如何忽略/删除/排除查找结果

Account.aggregate([
        {
            $match: {
                type: {$eq: type}
            },
        },
        {
            $lookup:
                {
                    from: "orders",
                    let: {accountId: {$toString : "$_id"}},
                    pipeline: [
                        {
                            $match:
                                {
                                    $expr:
                                        {
                                            $and:
                                                [
                                                    {$eq: ["$$accountId", "$usedAccountId"]},
                                                    {$eq: ["$orderState","COMPLETED"]
                                                ]
                                        }
                                }
                        }
                    ],
                    as: "orders"
                }
        }
    ])

通过上述查询,我​​得到以下结果。我想摆脱订单数组

[
 {
  //accountObject,
  orders: [
    //orderObject
 ]
 }
]

标签: mongodb

解决方案


推荐阅读