# Metricbeat 8.8.1 MongoDB module - Error fetching data replstatus: sort operation used more than the maximum bytes of RAM

**URL:** <https://discuss.elastic.co/t/metricbeat-8-8-1-mongodb-module-error-fetching-data-replstatus-sort-operation-used-more-than-the-maximum-bytes-of-ram/348057>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [November 27, 2023, 2:01pm UTC](https://discuss.elastic.co/t/metricbeat-8-8-1-mongodb-module-error-fetching-data-replstatus-sort-operation-used-more-than-the-maximum-bytes-of-ram/348057 "2023-11-27T14:01:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticforumuser5342](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@elasticforumuser5342](https://discuss.elastic.co/u/elasticforumuser5342)\
**Post date:** [November 27, 2023, 2:01pm UTC](https://discuss.elastic.co/t/metricbeat-8-8-1-mongodb-module-error-fetching-data-replstatus-sort-operation-used-more-than-the-maximum-bytes-of-ram/348057/1 "2023-11-27T14:01:25Z")

</div>

When trying to set up the mongodb.replstatus metricset on my replica set (MongoDB v3.6), I am given the error:  
`Error fetching data for metricset mongodb.replstatus: error getting replication info: could not get last operation timestamp in oplog: could not get cursor on collection 'oplog.rs': (OperationFailed) Executor error during find command :: caused by :: errormsg: "Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit."`

My oplog collection totals 16GB.

The error seems to happen when the the module attempts to sort the oplog in reverse natural order and get the first result.

From a quick look at the module's source code, the module appears to be executing the query `db["oplog.rs"].find({}).sort({ "-$natural": 1 })` to get the last entry in the oplog. Executing this query through the Mongo shell throws the same out of RAM error.

Executing the query `db["oplog.rs"].find({}).sort({ "$natural": -1 })` appears to provide the same ordering of results, and does not throw the same error.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 25, 2023, 4:01pm UTC](https://discuss.elastic.co/t/metricbeat-8-8-1-mongodb-module-error-fetching-data-replstatus-sort-operation-used-more-than-the-maximum-bytes-of-ram/348057/2 "2023-12-25T16:01:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![Richa\_Talwar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richa_talwar/32/119114_2.png) [@Richa\_Talwar](https://discuss.elastic.co/u/Richa_Talwar)\
**Post date:** [January 31, 2024, 11:37am UTC](https://discuss.elastic.co/t/metricbeat-8-8-1-mongodb-module-error-fetching-data-replstatus-sort-operation-used-more-than-the-maximum-bytes-of-ram/348057/3 "2024-01-31T11:37:45Z")

</div>

The issue has been [acknowledged](https://github.com/elastic/integrations/issues/8683) and fixed, and it should be available in the next beats release i.e 8.13.
