简体   繁体   中英

Mongodb - Does projection increase the execution time?

Lets say I have 50 fields in my document.

When I use projection, and just select 4 fields, does my execution time increase or decrease?

How does mongodb handle it?

  1. Does mongodb fetch the document, then filter the fields and return?
  2. Does mongodb fetch the selected fields instead of the whole document and return?
  3. Does it work different for find and aggregate ?

I believe 1st option will increase the execution time, while 2nd option will decrease it.

well it all depends I guess... depends what your search criteria are. It can only be point 1 in my opinion (or it should be heavily optimized), since any filtering or aggregation or whatever can be on fields that aren't in the projection. and btw.... define 'fetch'. fetch to the client, i would say no, 'fetched' on the server yes. In general I would say that, if your queries are not that complex, even if projection takes some additional time, it will balans with the total time in transmitting the data to the client. All in all we are talking milliseconds here and overall transmission times and delays are harder to surpress than optimizing DB queries.

In addition, I have found the following (More technical than my opinion): https://dba.stackexchange.com/questions/198444/how-mongodb-projection-affects-performance

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