I'm joining two collections, but the result of trends is an array, each item always has only one trend, how do I remove the trend inside array?
'Items' collection:
{
"itemid" : "370",
"name" : "A"
},
{
"itemid" : "378",
"name" : "B"
}
'Trends' collection
{
"itemid" : "370",
"max" : "715705",
},
{
"itemid" : "378",
"max" : "35346",
}
Command executed:
db.items.aggregate([
{
$lookup: {
from: "trends",
localField: "itemid",
foreignField: "itemid",
as: "trend"
}
}
])
Result:
{
"itemid" : "370",
"name" : "A",
"trend" : [ // unexpected array, the result is always a single 'trend'
{
"itemid" : "370",
"max" : "715705",
}
]
},
...
Expected:
{
"itemid" : "370",
"name" : "A",
"trend" : { // yeah, without array
"itemid" : "370",
"max" : "715705",
}
},
...