Hello everyone,
I have 3 collections “Product”, “Shop” and “Stock”.
Here my steps :
1 - $match “Product” > 6 909 documents
2 - $lookup “Product” and “Shop” > 6 909 documents
3 - $unwind this first result > 443 163 documents
4 - $lookup this first result and Stock
5 - $unwind this second resultat > 4 253 137 documents
After this 5 steps, I tried to add a “$count” stage, but i got “exceeded time limit” !
I also tried to add “$group” to merge the documents and reduce the number of documents, buf failed again !
Do you have any ideas ?
Followed are the collections :
— Product = 6909 documents
{
‘productId’: ‘141013’,
‘language’: ‘fr’
},
{
productId: ‘141014’,
language: ‘fr’
}
…
— Shop —
{
shopId: ‘101’,
name: ‘Paris’,
languages: [‘fr’]
},
{
shopId: ‘102’,
name: ‘Marseille’,
languages: [‘fr’]
},
{
shopId: ‘103’,
name: ‘Bordeaux’,
languages: [‘fr’]
}
…
Lookup between Product and Shop give :
{
productId: ‘141013’,
language: ‘fr’,
lookupShop: [
{ shopId: ‘101’, name: ‘Paris’, languages: [ ‘fr’ ] },
{ shopId: ‘102’, name: ‘Marseille’, languages: [ ‘fr’ ] },
{ shopId: ‘103’, name: ‘Bordeaux’, languages: [ ‘fr’ ] }
…
]
},
{
productId: ‘141014’,
language: ‘fr’,
lookupShop: [
{ shopId: ‘101’, name: ‘Paris’, languages: [ ‘fr’ ] },
{ shopId: ‘102’, name: ‘Marseille’, languages: [ ‘fr’ ] },
{ shopId: ‘103’, name: ‘Bordeaux’, languages: [ ‘fr’ ] }
…
]
},
…
After $unwind = 443 163 documents
{
productId: ‘141013’,
language: ‘fr’,
lookupShop:
{
shopId:101,
name: ‘Paris’,
languages:[‘fr’]
}
},
{
productId: ‘141013’,
language: ‘fr’,
lookupShop:
{
shopId:102,
name: ‘Marseille’,
languages:[‘fr’]
}
},
{
productId: ‘141013’,
language: ‘fr’,
lookupShop:
{
shopId:103,
name: ‘Bordeaux’,
languages:[‘fr’]
}
},
{
productId: ‘141014’,
language: ‘fr’,
lookupShop:
{
shopId:101,
name: ‘Paris’,
languages:[‘fr’]
}
}
…
— Stock
{
productId: ‘141013’,
sizeId: ‘01’,
shop:
{
shopId: ‘101’,
name: ‘Paris’
}
},
{
productId: ‘141013’,
sizeId: ‘02’,
shop:
{
shopId: ‘101’,
name: ‘Paris’
}
},
{
productId: ‘141013’,
sizeId: ‘01’,
shop:
{
shopId: ‘102’,
name: ‘Marseille’
}
},
…
Lookup with Stock with keys productId and shopId.
After $unwind = 4 253 137 documents