Answer the question
In order to leave comments, you need to log in
How to filter lookup aggregation results in MongoDB?
Good day. There is the following task.
There is an Event entity that has its own description, which has its own list of organizers in the form of an array of links and a list of workshops (the Workshop entity).
const EventSchema = new Schema(
{
title: {type: String, default:'', required: true},
description: {type: String, default:''},
startDate: {type: Date, default: Date.now, required: true},
founders: [{ type: Schema.Types.ObjectId, ref: 'User' }],
workshops: [{ type: Schema.Types.ObjectId, ref: 'Workshop' }],
});
const WorkshopSchema = new Schema(
{
title: {type: String, default:'', required: true},
description: {type: String, default:''},
event:{ type: Schema.Types.ObjectId, ref: 'Event' },
actors: [{ type: Schema.Types.ObjectId, ref: 'User' }],
});
db.getCollection('workshops').aggregate([
{
$lookup:
{
from: "events',
localField: "event",
foreignField: "_id",
as: "events"
}
}
])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question