简体   繁体   中英

How to optimize a list all mongoose query?

In the last few days I was busy trying to improve & optimize as mush as I can the mongoose queries for a website. The main thing I found for that was to use indexes which I've already done. But there's a problem... In my mongo schemas I have few "list all" queries , what I mean by that is : A query that will return everything from that model and it doesn't have any parameter .

I'm currently working on NodeJS v8.15.1 with ExpressJS and MongoDB v4.0.6

The kind of query I'm talking about , and the example below is one of my actually queries :

ModelSchema.statics.listAll = function ( callback ){
 try {
  return  this.find( {}, callback ).select({"x":0,"y":0});
 } catch (err) {
  console.log(err);
  return null;
 }
};

As you can see , I'm trying to get everything from that model excepting the x & y fields.

The query is perfectly working , there isn't any problem. As long as it doesn't use any indexed field it won't run faster or anything like that. But I wonder if there is a way to optimize it ?

Thank you very much for help!

我想我已经找到了答案:我可以通过缓存请求来解决这个问题,并在每次更改时再次查询它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM