# Error retrieving collection totals from Mongo instance

**URL:** <https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [May 28, 2019, 7:21am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007 "2019-05-28T07:21:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [May 28, 2019, 7:21am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/1 "2019-05-28T07:21:07Z")

</div>

Hello,  
I'm using metricbeat v6.3 & kibana v6.7.1, recently I'm trying to add my mongoDB stats to metricbeat dashboard and enabled module on mongodb under /etc/metricbeat/module.d/mongodb.yaml using following command.

`sudo metricbeat modules enable mongodb`

But when I restart the metricbeat service, I do see that metricbeat logs are showing some errors . getting mongodb stats.

```
|2019-05-28T07:10:42.802Z|ERROR|collstats/collstats.go:66|Error retrieving collection totals from Mongo instance|
|---|---|---|---|
|2019-05-28T07:10:42.820Z|ERROR|schema/schema.go:41|Error on field 'mb': Missing field: mb, Error: Key mapped not found|
|2019-05-28T07:10:42.820Z|ERROR|schema/schema.go:41|Error on field 'mb': Missing field: mb, Error: Key mappedWithJournal not found|
|2019-05-28T07:10:42.820Z|ERROR|mapstriface/mapstriface.go:80|Error accessing sub-dictionary `opcountersRepl`|
|2019-05-28T07:10:42.820Z|ERROR|mapstriface/mapstriface.go:80|Error accessing sub-dictionary `storageEngine`|
|2019-05-28T07:10:42.966Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-28T07:10:42.966Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-28T07:10:42.968Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-28T07:10:42.968Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-28T07:10:42.970Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-28T07:10:42.970Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-28T07:10:42.971Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-28T07:10:42.971Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-28T07:10:42.976Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-28T07:10:42.976Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-28T07:10:42.978Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|

```

My mongodb instance can be directly accessed through localhost and port is 27017. Following is my metricbeat configuration file.

```
- module: mongodb
  hosts: ["localhost:27017"]
  period: 10s
  enabled: true 

```

Any help would be greatly appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![Kaiyan\_Sheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaiyan_sheng/32/38247_2.png) [@Kaiyan\_Sheng](https://discuss.elastic.co/u/Kaiyan_Sheng)\
**Post date:** [May 28, 2019, 2:37pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/2 "2019-05-28T14:37:29Z")

</div>

Hello @madurad, thanks for all the detailed information. By looking at your metricbeat mongodb configuration, it appears to be you are missing the part that enables metricsets in mongodb module, for example `metricsets: ["dbstats", "status", "collstats", "metrics", "replstatus"]`. This might help [https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-module-mongodb.html#\_example\_configuration\_23](https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-module-mongodb.html#_example_configuration_23). Can you please add the missing `metricsets` line into your config and restart metricbeat?

---

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [May 29, 2019, 3:09am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/3 "2019-05-29T03:09:42Z")

</div>

Hi @Kaiyan_Sheng Thanks for replying, I'll change those configurations and update you.

Thanks.

---

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [May 29, 2019, 4:19am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/4 "2019-05-29T04:19:17Z")

</div>

@Kaiyan_Sheng I added the metrics and now my .yaml file looks like below.

```
- module: mongodb
  hosts: ["localhost:27017"]
  metricsets: ["dbstats", "status", "collstats"]
  period: 10s
  enabled: true

```

But still getting the same error, could you please look more in to this.

```
|2019-05-29T04:00:31.439Z|ERROR|collstats/collstats.go:66|Error retrieving collection totals from Mongo instance|
|---|---|---|---|
|2019-05-29T04:00:31.445Z|ERROR|mapstriface/mapstriface.go:80|Error accessing sub-dictionary `opcountersRepl`|
|2019-05-29T04:00:31.445Z|ERROR|mapstriface/mapstriface.go:80|Error accessing sub-dictionary `storageEngine`|
|2019-05-29T04:00:31.445Z|ERROR|schema/schema.go:41|Error on field 'mb': Missing field: mb, Error: Key mapped not found|
|2019-05-29T04:00:31.445Z|ERROR|schema/schema.go:41|Error on field 'mb': Missing field: mb, Error: Key mappedWithJournal not found|
|2019-05-29T04:00:31.511Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-29T04:00:31.511Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-29T04:00:31.513Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-29T04:00:31.514Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-29T04:00:31.515Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|
|2019-05-29T04:00:31.515Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-29T04:00:31.517Z|ERROR|schema/schema.go:41|Error on field 'db': Missing field: db, Error: Key db not found: key not found|
|2019-05-29T04:00:31.517Z|ERROR|schema/schema.go:41|Error on field 'collections': Missing field: collections, Error: Key collections not found|

```

Thanks

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [June 4, 2019, 7:07am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/5 "2019-06-04T07:07:43Z")

</div>

It seems the output from your mongodb instance misses some keys. What version of mongodb are you using?

---

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [June 4, 2019, 7:47am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/6 "2019-06-04T07:47:32Z")

</div>

@ruflin MongoDB version : v3.4

---

<div class="post-metadata">

**Author:** ![Kaiyan\_Sheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaiyan_sheng/32/38247_2.png) [@Kaiyan\_Sheng](https://discuss.elastic.co/u/Kaiyan_Sheng)\
**Post date:** [June 4, 2019, 2:54pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/7 "2019-06-04T14:54:38Z")

</div>

By looking at the MongoDB 3.4 documentation, seems like these keys are supported for 3.4:  
[https://docs.mongodb.com/v3.4/reference/command/serverStatus/#opcountersrepl](https://docs.mongodb.com/v3.4/reference/command/serverStatus/#opcountersrepl)  
[https://docs.mongodb.com/v3.4/reference/command/serverStatus/#storageEngine](https://docs.mongodb.com/v3.4/reference/command/serverStatus/#storageEngine)

Besides that, we also did some changes in [mapstriface.go](https://github.com/elastic/beats/blob/master/libbeat/common/schema/mapstriface/mapstriface.go#L93) in newer version of Metricbeat. I see you are using metricbeat v6.3 for now, is is possible to upgrade metricbeat to a newer version?

---

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [June 6, 2019, 9:07am UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/8 "2019-06-06T09:07:34Z")

</div>

@Kaiyan_Sheng which version do you recommend ?

---

<div class="post-metadata">

**Author:** ![Kaiyan\_Sheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaiyan_sheng/32/38247_2.png) [@Kaiyan\_Sheng](https://discuss.elastic.co/u/Kaiyan_Sheng)\
**Post date:** [June 6, 2019, 1:57pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/9 "2019-06-06T13:57:06Z")

</div>

Based on the code [https://github.com/elastic/beats/blob/6.4/libbeat/common/schema/mapstriface/mapstriface.go#L98](https://github.com/elastic/beats/blob/6.4/libbeat/common/schema/mapstriface/mapstriface.go#L98), 6.4 version or above should have this fix. If you want to give it a try, that would be great!

---

<div class="post-metadata">

**Author:** ![madurad](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@madurad](https://discuss.elastic.co/u/madurad)\
**Post date:** [June 11, 2019, 1:31pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/10 "2019-06-11T13:31:49Z")

</div>

@Kaiyan_Sheng I'll try upgrade it to 6.4 or above and get back to you.

---

<div class="post-metadata">

**Author:** ![Kaiyan\_Sheng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kaiyan_sheng/32/38247_2.png) [@Kaiyan\_Sheng](https://discuss.elastic.co/u/Kaiyan_Sheng)\
**Post date:** [June 11, 2019, 1:42pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/11 "2019-06-11T13:42:29Z")

</div>

@madurad Thank you!

---

<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:** [July 9, 2019, 1:42pm UTC](https://discuss.elastic.co/t/error-retrieving-collection-totals-from-mongo-instance/183007/12 "2019-07-09T13:42:30Z")

</div>

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