如何从mongodb中的另一个集合中获取字段值的总和

时间:2017-06-08 10:13:53

标签: node.js mongodb

我有两个集合,一个是旅行,另一个是装运。一次旅行可以有多个货物。

货件架构:

_id: {
        type: String,
        required: true
    },
    trip_id: {
        type: String,
        required: true
    },
    traveller_email_id: {
        type: String,
        required: true
    },
    email_id: {
        type: String,
        required: true
    },
    item_name: {
        type: String,
        default: true
    },
    description_of_shipment: {
        type: String,
        default: ''
    },
    required_weight: {
        type: Number,
        required: true
    },
    required_price: {
        type: Number,
        required: true
    },
    pickup_needed: {
        type: String,
        enum: ['No', 'Yes'],
        default: 'No',
        required: true
    },
    pickup_address: {
        type: String,
        default: ''
    },
    recipient_name: {
        type: String,
        required: true
    },
    recipient_place_name: {
        type: String,
        required: true
    },
    recipient_address: {
        type: String,
        required: true
    },
    recipient_contact_number: {
        type: String,
        required: true
    },
    order_number: {
        type: String,
        default: ''
    },
    accepted_status: {
        type: String,
        enum: ['Declined', 'Accepted', 'Requested','Transit','Pending','Delivered'],
        default: 'Requested',
        required: true
    }
}

我想得到" required_weight"每次旅行。我通过trip_id外键加载旅行表和发货表。

0 个答案:

没有答案