exports.main = async (event, context) => {
return await db.collection("demoping").aggregate().match({
nsid:"989f4e215ecb612200340cad70da848c"
}).lookup({
from: 'demonews',
localField: 'nsid',
foreignField: '_id',
as: 'nsArr'
}).replaceRoot({
newRoot: $.mergeObjects([ $.arrayElemAt(['$nsArr', 0]), '$$ROOT' ])
}).sort({
"posttime":-1
})
.end();
}
这是我写了一个聚合,我想要将demonews里面素有的数据都拿过来,但是demoping里面出先了重复字段名称,那么怎么处理那?
用project
db.collection("demoping").aggregate().match({
nsid:"989f4e215ecb612200340cad70da848c"
}).project({
content: 0,
openid: 0
}).lookup({
from: 'demonews',
localField: 'nsid',
foreignField: '_id',
as: 'nsArr'
}).replaceRoot({
newRoot: $.mergeObjects([ $.arrayElemAt(['$nsArr', 0]), '$$ROOT' ])
}).sort({
"posttime":-1
})
.end();