Hello. Worth Monga, version 3.4.

There are collections of children and parents.

Each document from parents belongs to one of the children, that is

name: 'test', parent: ObjectID('xxxxxxxxxxxxxxxxxxxxxxxx') 

There are about 5000 documents in the orders collection, and when I try to get them, I get an error that you cannot use the aggregate in a collection larger than 16 megabytes.

The question is how do I get all the documents by writing down the user name from the users collection (only the name, not the whole document)

Current request:

 DB.children.aggregate([ { $lookup: { from: 'parents', localField: 'parent', foreignField: '_id', as: 'parentFull' // ΠΏΠΎΠ»Π½Ρ‹ΠΉ Π΄ΠΎΠΊ, Π° Ρ…ΠΎΡ‡Ρƒ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ имя } } ]); 

Error text

 {"name":"MongoError","message":"aggregation result exceeds maximum document size (16MB)","ok":0,"errmsg":"aggregation result exceeds maximum document size (16MB)","code":16389,"codeName":"Location16389"} 

    1 answer 1

    No one could help, he figured out himself and I hope someone will help.

     DB.children.aggregate([ // Если Π½Π°Π΄ΠΎ сортируСм {$sort: {_id: -1}}, { $lookup: { from: 'parents', // Π΄ΠΎΡΡ‚Π°Ρ‚ΡŒ ΠΈΠ· ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ parents localField: 'parent', // Π³Π΄Π΅ parent ΠΈΠ· ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ children foreignField: '_id', // Ρ€Π°Π²Π΅Π½ _id ΠΈΠ· ΠΊΠΎΠ»Π»Π΅ΠΊΡ†ΠΈΠΈ parents as: 'parentFull' // ΠΏΠΎΠ»ΠΎΠΆΠΈΡ‚ΡŒ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Π² parentFull } }, // Π·Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ имя ΠΈΠ· parentFull Π² parentName { $addFields: { parentName: '$parentFull.name' } }, // Π£Π΄Π°Π»ΠΈΡ‚ΡŒ parentFull { $project: { parentFull: 0 } } ], (err, ok) => { if (err) throw err; }); 

    Thus, we have registered the name of the parent to each child, instead of writing full information about him. I left very detailed comments)) if something is wrong, correct.