Home > Enterprise >  How to properly use indexes in mongoose?
How to properly use indexes in mongoose?

Time:11-16

I'm new to mongoose and mangodb. Recently, I've noticed that my GCP compute engine instance(Ubuntu) sometimes runs at 100% CPU load. When I run the htop command, mongod.conf is always at the top of the list. I guess this is because I'm not using any index in my Mongoose schema. Could someone give me clarification on the following questions?

  1. Should I add indexes for all query fields, if I use queries with multiple filters? (I use more than 8 query fields)
  2. Does the order of query filters affect performance?
  3. If I add indexes to my mongoose schema, does that build indexes for existing documents?
  4. Should I add indexes for sort fields such as updatedAt or createdAt?
  5. Is it necessary to use indexes on documents that have only less than 4 fields?
  6. How can I find which query is taking too much time?

Thanks

CodePudding user response:

  1. => NO (use enter image description here

  • Related