Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoose query low performance when using with populate

I need help with this query. I am querying 8000 documents in AppVisitorwith 4 collections populated.But it is not returning any result. Means it get stuck and after some time nodejs server return 404 error for route in which this query is executed.

 let Keys = yield AppVisitor.find(condition).sort({ createdAt: -1 })
                .populate({ path: 'userDeatils' })
                .populate({ path: 'details' })
                .populate({
                    path: 'skills',
                    match: {
                        $and: [{ value: { $ne: '' } }, { value: { $ne: null } }, { value: { $not: /({R[\d]+})/g } }]
                    }
                })
                .populate({ path: 'courses' });
like image 787
Abhishek Singh Avatar asked Jun 09 '26 17:06

Abhishek Singh


1 Answers

I guess trying to restructure your collections could help, and use populate function less as its quite a heavy operation.Make sure you know what you are doing when you use populate.

like image 183
Kay Avatar answered Jun 11 '26 18:06

Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!