查询mongo:在集合的所有文档中查找数组的计数

时间:2018-09-04 21:07:12

标签: node.js mongodb

查询mongo以查找收款公司每个文档中所有汽车阵列的数量

我是mongo的新手,我

db.company.find()->但是我该如何选择数组,对于所有数组也是如此

collection company : {

    {   
       "_id": "5b8ed214b460e7c17c5a33f9",
        "company_location": "USA",
        "company_name": "gmc",
        "__v": 0,
        "cars": [{
                "_id": "5b8ed214044b2509466eca2e",
                "model": "TERRAIN",
                "year": 2013,
                "PriceInINR": 3851710,
                "trim": "SLE2 FWD",
                "engine": "SPORT UTILITY 4-DR",
                "body": "2.4L L4 DOHC 16V FFV",
                "color": "Yellow",
                "transmission_type": "Manual",
                "dealer_id": "5b8e7ce7065fa50bee095072"
            },
              {------},
              {------}   
}

1 个答案:

答案 0 :(得分:0)

首先,将查询分配给变量... 然后计算汽车阵列...如下所示

class Table_AView(ModelView):
    datamodel = SQLAInterface(Table_AView)
    label_columns = {'Field_A':'A'}
    list_columns = ['Field_A']

如果通过_id找到obj [index],则始终为0。