在mongodb中的投影字段中查找

时间:2018-12-21 10:58:29

标签: mongodb lookup

从mongodb的投影字段中查找...

我有这种类型的代码查询,我想要从$projection中找到的公司ID中获取公司数据……

{
    $project: {
        _id: 1,
        id: "$_id",
        lead_source_id: 1,
        media_provider_company_id: 1,
        media_provider_company: {
            $arrayElemAt: ["$media_provider_company", 0]
        },
        lead_source: {
            $arrayElemAt: ["$lead_source", 0]
        },
        category: {
            $arrayElemAt: ["$category", 0]
        },
        disputes_requests: {
            $arrayElemAt: ["$disputes_requests", 0]
        },
        first_name: 1,
        last_name: 1,
        title: 1,
        email: 1,
        category_id: 1,
        is_provider: 1,
        cell_phone: 1,
        work_phone: 1,
        home_phone: 1,
        address_line_1: 1,
        address_line_2: 1,
        city: 1,
        state: 1,
        zip: 1,
        ip_address: 1,
        loan_amount: 1,
        loan_type: 1,
        LTV: 1,
        fico: 1,
        property_type: 1,
        budget: 1,
        created_on: 1,
        is_disputed: 1,
        dispute_request: 1,
        dispute_action: 1,
        dispute_count: 1,
        price: 1,
        }
}
{
    $project: {
        _id: 1,
        id: 1,
        lead_source_id: 1,
        media_provider_company_id: 1,
        media_provider_company: {
            $ifNull: ["$media_provider_company.name", ""]
        },
        lead_source: {
            $ifNull: ["$lead_source.name", ""]
        },
        category: "$category.name",
        disputes_requests: {
            id: "$disputes_requests._id",
            _id: 1,
            dispute_comment: 1,
            company_id: 1,
            status: 1,
            action_comment: 1
        },
        first_name: 1,
        last_name: 1,
        title: 1,
        email: 1,
        category_id: 1,
        is_provider: 1,
        cell_phone: 1,
        work_phone: 1,
        home_phone: 1,
        address_line_1: 1,
        address_line_2: 1,
        city: 1,
        state: 1,
        zip: 1,
        ip_address: 1,
        loan_amount: 1,
        loan_type: 1,
        LTV: 1,
        fico: 1,
        property_type: 1,
        budget: 1,
        created_on: 1,
        is_disputed: 1,
        dispute_request: 1,
        dispute_action: 1,
        dispute_count: 1,
        lead_source_price_id: {
            $ifNull: ["$price._id", ""]
        },
        price: {
            $ifNull: ["$price.price", "Not Set"]
        }
    }
}

我想要来自company.id的公司数据,这是从预测中获得的.. 所以请为此帮我...

0 个答案:

没有答案