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?
- Should I add indexes for all query fields, if I use queries with multiple filters? (I use more than 8 query fields)
- Does the order of query filters affect performance?
- If I add indexes to my mongoose schema, does that build indexes for existing documents?
- Should I add indexes for sort fields such as
updatedAt
orcreatedAt
? - Is it necessary to use indexes on documents that have only less than 4 fields?
- How can I find which query is taking too much time?
Thanks
CodePudding user response: