Closed eZubia closed 5 years ago
Save issue that you... Could you somehow fix it? my other option is now to build with skip...
const aggregationPipelines = [
{
$match: {
authorities: { $in: ["ROLE_ARCHITECT"] },
isActivated: true,
isClosed: false,
name: {
$regex: new RegExp(architectName, "i")
},
country: !isEmpty(country) ? { $in: [country] } : { $ne: [country] }
}
},
{
$lookup: {
from: "profiles",
localField: "_id",
foreignField: "_user",
as: "profile"
}
},
{
$project: {
_id: true,
avatar: true,
lastConnectionDate: true,
isOnline: true,
"profile.name": true,
"profile.categories": true,
"profile.skills": true,
"profile.styles": true,
"profile.website": true,
"profile.portfolio.images": true,
"profile.portfolio.title": true,
"profile.portfolio._id": true,
"profile.portfolio.category": true,
"profile.services.type": true,
"profile.country": true,
"profile.favorite": true,
"profile.date": true
}
}
]
These are my pipes lines, then i
const profileAggregations = await User.aggregate(aggregationPipelines)
and when i try
const profiles = await User.aggregatePaginate(
profileAggregations,
options
)
Its just return the User element without the aggregation work....
I'm trying to use an aggregate query with the $lookup operation but isn't populate the id.
i'm using:
Node: 10.13.0 mongoose: 5.3.13 mongoose-aggregate-paginate-v2: 1.0.2
The query i'm trying to use is this:
{ $match: { $and: [ { 'guide_tour' : Types.ObjectId(<testid>)}, ] } }, { $lookup: { from: "node", localField: "node", foreignField: "_id", as: "node" } }, { $unwind: "$node", }, { $sort : { step : 1} }
And the result that i spect is this:
{ _id: 5d44d8cb77e6a285ce82d7ee, deleted: { isDeleted: false }, guide_tour: 5d44d8cb77e6a2400d82d7e6, node: { _id: 5d436f3e187e6d000653eff8, node_name: 'None /home link-home Inicio ', node_level: 'ELEMENT'} __v: 0 }
And this is the result with the mongoose-aggregate.
{ _id: 5d44d8cb77e6a2023482d7f9, deleted: { isDeleted: false }, guide_tour: 5d44d8cb77e6a2400d82d7e6, node: 5d447c0015cddf0006965f4a, description: 'Da clic en Aceptar', step: 19, requested: 0, __v: 0 }
With the simple aggregation it works fine.