使用DBRef进行聚合查找

时间:2018-06-05 23:51:18

标签: mongodb aggregation-framework morphia

有两个集合时是否可以使用聚合框架查找阶段,在源集合中有一个DBREF,而dest集合上有一个长_id?

我的聚合查询是:

db.carAgent.aggregate([ { $lookup: { from: "country", localField: "country", foreignField: "_id", as: "country" } }])

示例集合数据是:

> db.country.findOne()
{
        "_id" : NumberLong(1),
        "countryId" : "AD",
        "countryName" : "Andorra",
        "phoneCode" : "376",
        "iso3" : "AND"
}
> db.carAgent.findOne()
{
        "_id" : NumberLong(5),
        "name" : "ALAMO ehi",
        "country" : DBRef("country", NumberLong(97)),
        "desc" : "Alamo DC",
        "status" : true,
        "xmlType" : "AL",
        "company" : "ALAMO"
}
>

0 个答案:

没有答案