Optimizing mongodb queries for the first time.

in mongodb •  8 years ago 

https://docs.mongodb.com/manual/reference/method/db.setProfilingLevel/ is the first place, where I knew, I can do something. The below snippet allowed me to test & verify the efforts quickly.

db.setProfilingLevel(0)
db.system.profile.drop()
db.setProfilingLevel(1, 100); //100, 500, 1000, 2000
db.system.profile.find({}, {query: 1, ns: 1, millis: 1}).limit(10).sort( { millis : -1 } ).pretty()

Query explainer: db.collection.find(query).explain('executionStats');

Learnt complex/compound queries can make use of individual indexes.

Available indexes & their sizes can be seen using db.collection.stats()

mongotop a neat tool.

Hopefully, this would be a real optimization.

Note to self:

  1. Keep an eye on index size
  2. Try to rewrite logic & incorporate optmization at design level. So, the queries will be faster with only default and simple indexes.
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @mudivili! You received a personal award!

1 Year on Steemit

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @mudivili! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!