I cannot query with two collections joining with $lookup

时间:2017-08-05 11:10:45

标签: mongodb aggregation-framework database

can anyone help me? I have two collections. And I want to query joining these two collections. I used aggerate method and $lookup but I still get error.

First collection (bill_history)

{
    "_id" : ObjectId("59856d04f81b08b4f61a6bea"),
    "id" : 262.0,
    "category" : "Beauty",
    "holdername" : "Blue Planet",
    "serviceid" : 156.0,
    "keyword" : "BEA",
    "source" : "8602",
    "amount" : 84.0,
    "billfrequency" : "daily",
    "smsfrequency" : "1sms per day",
    "type" : "Subscription",
    "description" : "Beauty Tips",
    "status" : "running",
    "startdate" : "2016-09-10 11:28:47",
    "enddate" : "1970-01-01 00:00:01",
    "contact" : "12399188",
    "remark" : "Content SMS Service (CMS)"
}

Second Collection (service)

{
    "_id" : ObjectId("59856d04f81b08b4f61a6bea"),
    "id" : 262.0,
    "category" : "Beauty",
    "holdername" : "Blue Planet",
    "serviceid" : 156.0,
    "keyword" : "BEA",
    "source" : "8602",
    "amount" : 84.0,
    "billfrequency" : "daily",
    "smsfrequency" : "1sms per day",
    "type" : "Subscription",
    "description" : "Beauty Tips",
    "status" : "running",
    "startdate" : "2016-09-10 11:28:47",
    "enddate" : "1970-01-01 00:00:01",
    "contact" : "12399188",
    "remark" : "Content SMS Service (CMS)"
}

My Mongo Query Code is as below.

db.bill_history.aggregate([
    { $lookup : {
        from : "service",
        localField : "ref",
        foreignField : "keyword",
        as : "embaddedData"
        }
    }
])

Error message and code are as below.
"error msg":"exception: Unrecognized pipeline stage name: '$lookup'", "code" : 16436,

0 个答案:

没有答案