When I directly use find to return all fields, the result is as follows, the query time is 155
If you limit the return field, the query time will be longer, 251
Why? If I limit the fields to be returned, the number of bytes of characters to be queried will decrease. shouldn’t the transmission be faster?
The implementation plan you posted mainly revealed the following information:
1. First Implementation Plan:
Because no index is used, collscan revealed that it is a full collection scan, so it can be considered to create an index.
2. Second Implementation Plan:
Is still a full collection scan, and will meet the conditions of documents scan to memory, and complete the projection memory, select the specified field, and return to the field. In this way, it seems that time will consume more.
Although only the specified field is returned, only the entire documents can be returned when reading the storage and scanning the entire collection. This is probably some basic principles of database: read and write according to documents; It should be added that some column databases are stored by columns, which is the kind of situation you imagine. However, many databases are saved by rows or by documents.
If you create a covered index on the specified field and only return the specified field, this is the most efficient because only scanning the index can return the specified field.
Love MongoDB！ Have fun！