Answer the question
In order to leave comments, you need to log in
How to build an aggregate query for mongoose?
Hello! I have a collection of posts:
{
definition: { type: mongoose.Types.ObjectId, ref: 'Definition' }
}
{
title: String,
likes: Number
}
Answer the question
In order to leave comments, you need to log in
mongus populate will not be able to combine with aggregation in one query,
try something like this
Post.aggregate([
{
$lookup: {
from: 'definitions',
localField: 'definition',
foreignField: '_id',
as: 'definitions'
}
},
{
$match: {
'definitions.likes': { $gte: 10 }
}
}
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question