Hello, I use a pipeline to get some data from collection A, the document Da in collection A looks like:
{
_id : "AAA",
status: "active",
desc: "the desc of AAA",
creation_date: "2019-05-11T10:59:55.627+00:00"
}
At the end of the pipeline there is a $lookup stage, it is:
bson.D{{
"$lookup", bson.D{
{"from", "alias"},
{"localField", "_id"},
{"foreignField", "place_id"},
{"as", "aliases"}
}
}}
The document in collection “alias” looks like
{
_id: ObjectId("605af6b150d88dccc7bbadd8"),
place_id: "AAA",
content: "it is the alias of AAA"
}
The returned document from the pipeline should be:
{
_id : "AAA",
status: "active",
desc: "the desc of AAA",
creation_date: "2019-05-11T10:59:55.627+00:00",
aliases: ["it is the alias of AAA"]
}
The issue is: the aliases field is not in the result, only document Da is returned. It seems the $lookup stage not work, but all stages ahead of $lookup stage works fine, otherwise Da will not be returned.
But, if I manually add an “aliases” field in the document Da in collection A, even the “aliases” is empty, i.e. if I change Da to:
{
_id : "AAA",
status: "active",
desc: "the desc of AAA",
creation_date: "2019-05-11T10:59:55.627+00:00",
aliases:""
}
then if I execute the same pipeline, with the ending stage is the $lookup, the return result of the pipeline will be:
{
_id : "AAA",
status: "active",
desc: "the desc of AAA",
creation_date: "2019-05-11T10:59:55.627+00:00",
aliases: ["it is the alias of AAA"]
}
in other words, the pipeline running correctly. the $lookup seems worked.
I don’t know why such issue happened, thanks for the help.