node.js - Mongoose populate option and query time -


i working on platform use mongoose .populate number of times in queries, turn on mongoose debug mode , find there hardly difference in query execution time (for 100 document , there will 100000 doc in future) using populate , without using populate.

i know populate doing finone query internally , question is, using .populate increase query time or anyways going effect performance if number of record reaches millions. there alternate can choose increase performance

in general, you're correct - want avoid using populate() since issue query each row. keep in mind full round-trip server. mongo doesn't have sort of concept join, when populate you're issuing additional query each row in returned set.

the technique work around denormalize data - don't design mongo database relational one. mongo docs have lots of information on how this. https://docs.mongodb.org/manual/core/data-model-design/ 1 important thing keep in mind mongo design never want have subdocument unbounded growth. due way mongo space allocation , paging works, can cause severe performance problems, if you're in situation it's best normalize.

another common technique subdocument caching. take partial data "joined" collection , cache on collection you're querying. in case, you're trading space performance because have duplicate data. also, you'll have make sure keep data updated whenever there's change. mongoose, easy post-save hook on model of foreign collection.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -