记录一个复杂的mongo查询

db.XXXXXX.aggregate([
    {
        "$match": {
            "paperId": 18, "status": 2
        }
    },
    {
        "$unwind": "$examSections"
    },
    {
        "$unwind": "$examSections.details"
    },
    {
        "$match": {
            "examSections.details.isGroup": 0, "examSections.details.choicetypeId": 29
        }
    }, {
        $group: {
            _id: { questionId: "$examSections.details.questionId" },
            questionId: { $first: "$examSections.details.questionId" },
            choicetypeId: { $first: "$examSections.details.choicetypeId" },
            answerNum: { $sum: 1 },
            erroNum: { $sum: { $cond: { if: { $eq: ["$examSections.details.isRight", 0] }, then: 1, else: 0 } } },
            choice_A_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_B_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_C_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_D_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_E_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_F_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_G_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } },
            choice_H_num: { $sum: { $cond: { if: { $eq: ["$examSections.details.myAnswer", ""] }, then: 1, else: 0 } } }
        }
    },
    {
        $project: {
            "_id": 0,
            "questionId": 1,
            "choicetypeId": 1,
            "answerNum": 1,
            "choice_A_num": 1,
            "choice_B_num": 1,
            "choice_C_num": 1,
            "choice_D_num": 1,
            "choice_E_num": 1,
            "choice_F_num": 1,
            "choice_G_num": 1,
            "choice_H_num": 1,
            "memberId": 1,

        }
    }
])

 

 

 

db.abcPo.aggregate([
    {
        "$match": {
            "sSubjectId": 1, "memberId": 1
        }
    }, {
        $group: {
            _id: { choicetypeId: "$choicetypeId" }, choicetypeIdCollectCount: { $sum: 1 }
        }
    },
    {
        $project: {
            "_id": 0,
            "choicetypeId": '$_id.choicetypeId',
            "choicetypeIdCollectCount": 1
        }
    }
])

 

db.updateRecordOrTranscriptOrPaperRecordDataDetailLogPo.updateMany(
{},
{
  "$rename":{"old":"new"}
}
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值