From fbabf0fb2c1ea8e5e6cca538d247e29829b2982b Mon Sep 17 00:00:00 2001 From: subham sarkar Date: Wed, 8 Jan 2025 11:54:24 +0530 Subject: [PATCH] metricbeat/module/mongodb: Improve logic --- metricbeat/module/mongodb/replstatus/info.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/metricbeat/module/mongodb/replstatus/info.go b/metricbeat/module/mongodb/replstatus/info.go index a57717fc268c..ef13042b8f04 100644 --- a/metricbeat/module/mongodb/replstatus/info.go +++ b/metricbeat/module/mongodb/replstatus/info.go @@ -112,6 +112,12 @@ func getOpTimestamp(collection *mongo.Collection) (uint32, uint32, error) { // querying without any sort, it will return the first entry in natural order. // When we sort in reverse natural order (i.e., $natural: -1), it will return // the last entry in natural order. + // + // The queries use optimizations like FindOne() and SetProjection() to limit + // the amount of data that needs to be scanned and processed. + // Projection is used to limit the fields returned in the query results i.e., we + // only need the timestamp (ts) field. FindOne() is used to retrieve a single + // document from the collection (limit: 1). var firstDoc struct { Timestamp time.Time `bson:"ts"`