2 / 3
Sep 2024

Hi all?
I need test my database. When I execute below aggregate query, returns empty array. In that case main collection has data and other collections are empty.

[ { $lookup: { from: 'MM_AdministrationCode', localField: '_id', foreignField: '_id', as: 'administrationCode' } }, { $lookup: { from: 'MM_Manpower', localField: '_id', foreignField: '_id', as: 'manpower' } }, { $lookup: { from: 'MM_Arena', localField: '_id', foreignField: 'complexId', as: 'arenas' } }, { $lookup: { from: 'MM_FileMulti', localField: '_id', foreignField: '_id', as: 'photos' } }, { $lookup: { from: 'MM_Ownership', localField: '_id', foreignField: '_id', as: 'ownership' } }, { $unwind: { path: '$administrationCode' } }, { $unwind: { path: '$manpower' } }, { $unwind: { path: '$photos' } }, { $unwind: { path: '$ownership' } }, { $unwind: { path: '$ownership.owners' } }, { $lookup: { from: 'MM_Organisation', localField: 'ownership.owners.ownerId', foreignField: '_id', as: 'ownership.owners.ownerInfo' } }, { $unwind: { path: '$ownership.owners.ownerInfo' } }, { $group: { _id: '$_id', owners: { $push: '$ownership.owners' }, complexName: { $first: '$complexName' }, introduction: { $first: '$introduction' }, photos: { $first: '$photos' }, administrationCode: { $first: '$administrationCode' }, manpower: { $first: '$manpower' }, arenas: { $first: '$arenas' } } }, { $project: { _id: 1, complexName: 1, introduction: 1, photos: 1, administrationCode: 1, owners: 1, arenas: 1, arenaCount: { $size: '$arenas' }, manpower: 1, workerCount: { $add: [ '$manpower.cheifNumber', '$manpower.trainerFemaleNumber', '$manpower.trainerMaleNumber', '$manpower.servantFemaleNumber', '$manpower.servantMaleNumber' ] } } } ]

Where is problem? I hope some one fix help me. Thank you.

It would make life easier to help look at your issues if you provided example data, preferably in a mongo playground environment with data setup.

Scanning the lookups are all the _ids the same in all collections for matching data? Is the PK the same in all collections?