我的MongoDB数据库中有许多集合。聚合工作很好,但我不能将一些字段推送到所需的输出,
收藏品A是:
{
_id: some mongodbID
//...fields
items: [
{
_id: someId,
color: someId <---- Im aggregate this with lookup
neededFieldToPush: 123
},
{
_id: someId,
color: someId <---- Im aggregate this with lookup
我的用例是在MongoDB中联合两个不同的集合,这两个集合具有大致相同的业务意义,但存储在两个不同的集合中。我在link找到了答案 因此,为了合并两个集合并创建视图,我使用下一个管道 // Here we do a union of the employees and freelancers using a single aggregation query.
db.createView(
"employeesAndFreelancers",
"employees",
[
{ $limit: 1 }, // 2. Keep only on