在mongoDB中填充之后如何查找字段

时间:2018-04-24 08:33:19

标签: javascript node.js mongodb mongoose

我有代码:

 schemeProductDetailsModel.find({})
        .populate({
            path: 'schemeProduct',
            model: schemeProductsMd
          })
        .populate({
            path: 'qrCode',
            model: qrcodesMd,
            match : {code : "TB00006"}
        })
        .exec();

它的回归:

[
        {
            "note": "ghi chú",
            "_id": "5adecfc654c19a0014f55032",
            "schemeProduct": {
                "quantityDeployed": 0,
                "quantityRemaining": 10,
                "_id": "5a7d089efeb222491ae36f9a",
                "product": "5a7bbf5bfeb222491acd2b54",
                "quantityDeploy": 10,
                "updatedAt": "2018-03-08T03:29:13.379Z"
            },
            "qrCode": {
                "_id": "5a7a6c89f36d283d3de73459",
                "code": "TB00006",
                "status": "5a7a6f07feb222491ab93fac"
            },
            "serial": "SR001",
            "dateFrom": "2018-04-24T00:00:00.000Z",
            "dateTo": "2018-04-25T00:00:00.000Z",
            "createdAt": "2018-04-24T06:33:42.032Z",
            "updatedAt": "2018-04-24T06:33:42.032Z",
            "__v": 0
        }
   ]

我希望在集合mongoDB中找到字段"code": 我想在找到"qrCode.code" : "TB00006"时返回,如果找到"qrCode.code" : "TB00007"则返回

[]

我希望你能帮助我...... 谢谢 对不起我的英语不好。 :(

0 个答案:

没有答案