Mongo database slow

Hello,

I have a question regarding optimizing performance of my application.
So far everything’s great when I have a low amount of entries, however when I get over 10K entries I start to notice how I need to wait 4-7 seconds every time I need to perform a db query.
I tried using limits client-sided, I did notice a small difference (1-3 sec better), but when I do it server sided I notice a huge difference (almost instant searches/queries).
I’m assuming it’s because of how Meteor and Mongo work, server being Mongo-db and client being Mini-mongo which is a synced copy of Mongo-db that is loaded locally onto client’s machine, and the client has to wait until all 10 000 get loaded into his mini-mongo, and only then he does his query with limit of 10/1000 items.

My question is:
How do I call queries like : (client-side)

tripList: function(){
return Trips.find({"userId" : {$eq: Meteor.userId()}}, {sort: {createdAt: -1}, limit:10});
},

Server-sided? If that makes any sense.

just setting limit 10 sever-sided wont cut it, I need to able to vary the limit, from 1000, to all 10K, because I need to keep CSV export with all 10 000.

examples:

currSearchCount.set(Trips.find(allExpr, {sort: {createdAt: -1}}).count());
return Trips.find(allExpr, {sort:{createdAt: -1}, limit:1000});

If I am understanding what your question is, you just want a dynamic limit set on your server DB query? Just set the limit as a variable to be passed to the function:

grabTrips(allExpr, lim) {
 return Trips.find(allExpr, {sort:{createdAt: -1}, limit: lim});
}
1 Like

Also, if your use case is a csv export, it will be much more performant to generate the csv on the server based on a query passed in from the client than to send all the data over the wire and generate the csv on the client side.

2 Likes