MONGO in the use of the process encountered a problem, the need is to MONGO library query to the data paging, MONGO library we know that will store large volumes of data, if there is more data in the library, this will be reported a query failed with error code, and ER ROR message ' Executor error during find Command:OperationFailed:Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit. '
According to the error, know that this is a sort of the wrong time, because the MONGO sort operation is in memory operation, will inevitably occupy memory, while the MONGO within a mechanism to limit the maximum memory of 32M, when the amount of data sorted more than 32M, will be reported above this error, The solution is like the above hint, one is to increase the MONGO of the sort of memory, this is generally operations to the tube, there are drawbacks, that is, the amount of data if again large, but also to add. Another way is to add index, this method is very convenient. Creating an index takes effect in a timely manner without restarting the service. It's not hard to create an index,
Db. Your Collection.createindex ({"Your field":-1}), here-1 for reverse, 1 for positive sequence;
Db. Your collecton.getindexes ();
These two statements, the first is to add an index, the second is the query index, if you look at the index field you just added, the index was added successfully. This time in your program to use the sort method, so that will not error and fast.
Adding an index can have some drawbacks, which can lead to slower data insertions than before because the index occupies space. In the light of the actual situation, the appropriate method should be used.
MongoDB Sort operation used more than the maximum 33554432 bytes of RAM