# Metricbeat exception from mongodb module

**URL:** <https://discuss.elastic.co/t/metricbeat-exception-from-mongodb-module/197503>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [August 30, 2019, 11:05am UTC](https://discuss.elastic.co/t/metricbeat-exception-from-mongodb-module/197503 "2019-08-30T11:05:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debashish\_Sen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/debashish_sen/32/53364_2.png) [@Debashish\_Sen](https://discuss.elastic.co/u/Debashish_Sen)\
**Post date:** [August 30, 2019, 11:05am UTC](https://discuss.elastic.co/t/metricbeat-exception-from-mongodb-module/197503/1 "2019-08-30T11:05:14Z")

</div>

**Unable to fetch metrics from mongos router using Metricbeat mongodb module**

Getting following response from metricbeat in kibana discover tab.

```auto
{
   "_index":"metricbeat-6.6.1-2019.08.30",
   "_type":"doc",
   "_id":"TPRy4WwBD8jWXe3om-Qlbcq",
   "_score":1,
   "_source":{
      "@timestamp":"2019-08-30T07:34:39.988Z",
      "metricset":{
         "host":<hostname>:<port>,
         "rtt":13591,
         "name":"status",
         "module":"mongodb"
      },
      "event":{
         "dataset":"mongodb.status",
         "duration":13591785
      },
      "error":{
         "message":"not authorized on admin to execute command { serverStatus: 1, $readPreference: { mode: \"secondaryPreferred\" }, $db: \"admin\" }"
      },
      "beat":{
         "name":<name>,
         "hostname":<hostname>,
         "version":"6.6.1"
      },
      "host":{
         //info
      },
      "meta":{
         //info
      }
   },
   "fields":{
      "@timestamp":[
         "2019-08-30T07:34:39.988Z"
      ]
   }
}

```

**Metricbeat version: 6.6.1**  
**Metricbeat Configuration**

```auto
    module: mongodb
    metricsets: ["dbstats", "status", "collstats"]
    enabled: true
    period: 10s
    hosts: [<host1>,<host2>]
    username: <username>
    password: <password>

```

**Mongos router version: 4.0.6**  
**Mongo user roles**

```auto
{
   "user":<username>,
   "db":"admin",
   "roles":[
      {
         "role":"root",
         "db":"admin"
      },
      {
         "role":"userAdmin",
         "db":"admin"
      },
      {
         "role":"dbOwner",
         "db":"admin"
      },
      {
         "role":"userAdminAnyDatabase",
         "db":"admin"
      }
   ]
}

```

Also, the below queries are working on mongo-shell from the same user

```auto
	db.runCommand({dbStats: 1})
	db.runCommand( { serverStatus: 1, } )
	db.runCommand( { serverStatus: 1, $readPreference: { mode: "secondaryPreferred" }} )

```

Thanks in advance.

---

<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:** [September 27, 2019, 11:05am UTC](https://discuss.elastic.co/t/metricbeat-exception-from-mongodb-module/197503/2 "2019-09-27T11:05:14Z")

</div>

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