我试图将多个文档的值聚合在一起,但无法做到,
db.doc1.find().pretty();
{
"addressId" : ObjectId("5901a5f83541b7d5d3293768"),
"socialId" : ObjectId("5901b0f6d318b072ceea44fb")
}
db.doc2.find().pretty();
{
"_id" : ObjectId("5901a5f83541b7d5d3293768"),
"address" : "Gurgaon",
"mob" : "9876543211"
}
db.doc3.find().pretty();
{
"_id" : ObjectId("5901b0f6d318b072ceea44fb"),
"fbURLs" : "http://www.facebook.com",
"twitterURLs" : "http://www.twitter.com"
}
我的查询
db.doc2.aggregate([
{ $match: { "_id" : ObjectId("5901a5f83541b7d5d3293768") } },
{
$lookup:
{
from: "doc1",
localField: "_id",
foreignField: "addressId",
as: "Doc2Details"
}
}
]).pretty();
db.doc3.aggregate([
{ $match: { "_id" : ObjectId("5901b0f6d318b072ceea44fb") } },
{
$lookup:
{
from: "doc1",
localField: "_id",
foreignField: "socialId",
as: "tireConfig"
}
}
]).pretty();
我想要来自Doc1的匹配值并结合doc2和doc3的值,有人可以帮我解决这个问题吗?