MongoDB Overflow sort stage buffered data usage exceeds internal limit

Error: Overflow sort stage buffered data usage of 33558657 bytes exceeds internal limit of 33554432 bytes

Causes: MongoDB has a 32MB limit on in-memory sort

Solutions: Find out what field is used by the sort and create index or compound index for that fields. This will avoid the in-memory sort

db.collection.ensureIndex({“a:1, “b”:1})

MongoDB Overflow sort stage buffered data usage exceeds internal limit