# Metricbeat 8.3.2 and mongo V5

**URL:** <https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [July 18, 2022, 2:07pm UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912 "2022-07-18T14:07:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajsolanki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsolanki/32/86859_2.png) [@rajsolanki](https://discuss.elastic.co/u/rajsolanki)\
**Post date:** [July 18, 2022, 2:07pm UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912/1 "2022-07-18T14:07:44Z")

</div>

FYI Metricbeat 8.3.1+ now supports mongo V5. So i downloaded 8.3.2 and configured against my 3 server cluster with replica set.

So if i add single server ( i have 3 server cluster with replica set in following template it works.

hosts: ["mymongoserver1:27017"]  
username: myuser  
password: mypassword

but if add multiple hosts

hosts: ["mymongoserver1:27017",” mymongoserver2:27017”,” mymongoserver3:27017”]  
username: myuser  
password: mypassword

I get following error.

```auto

{"log.level":"error","[@timestamp]:"2022-07-18T08:21:47.507-0500","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset mongodb.status: could not create mongodb client: could not create mongodb client: a direct connection cannot be made if multiple hosts are specified","service.name":"metricbeat","ecs.version":"1.6.0"}

```

So then i tried following template

hosts: ["mongodb://myuser:mypass@mymongoserver1:27017", " mongodb://myuser:mypass@mymongoserver2:27017", mongodb://myuser:mypass@mymongoserver3:27017"]

`{"log.level":"error","[@timestamp]":"2022-07-18T08:33:34.818-0500","log.origin":{"file.name":"module/wrapper.go","file.line":256},"message":"Error fetching data for metricset mongodb.status: failed to retrieve 'serverStatus': server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myuser:mypass@mymongoserver1:27017, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: dial tcp: address mongodb:// myuser:mypass@mymongoserver1:27017: too many colons in address },] }","service.name":"metricbeat","ecs.version":"1.6.0"}`

Any one know what am i missing ?

---

<div class="post-metadata">

**Author:** ![mtojek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mtojek/32/63863_2.png) [@mtojek](https://discuss.elastic.co/u/mtojek)\
**Post date:** [July 19, 2022, 10:44am UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912/2 "2022-07-19T10:44:17Z")

</div>

Interesting, could you please share formatted configuration you're using?

---

<div class="post-metadata">

**Author:** ![rajsolanki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsolanki/32/86859_2.png) [@rajsolanki](https://discuss.elastic.co/u/rajsolanki)\
**Post date:** [July 19, 2022, 1:03pm UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912/3 "2022-07-19T13:03:34Z")

</div>

Here is my config.

```auto
# Module: mongodb
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/8.3/metricbeat-module-mongodb.html

- module: mongodb
  metricsets:
    - dbstats
    - status
    - collstats
    - metrics
    - replstatus
  period: 10s

  # The hosts must be passed as MongoDB URLs in the format:
  # [mongodb://][user:pass@]host[:port].
  # The username and password can also be set using the respective configuration
  # options. The credentials in the URL take precedence over the username and
  # password configuration options.
  hosts: ["mymongoserver1:27017"]
  #hosts: ["mongodb://myuser:mypassword@mymongoserver1:27017"]
  #hosts: ["mongodb://myuser:mypassword@mymongoserver1:27017" ,"mymongoserver2:27017" , "mymongoserver3:27017"]
  #hosts: ["mymongoserver1:27017",”mymongoserver2:27017”,” mymongoserver3:27017”]
  #hosts: ["mongodb://mymongoserver1:27017?authMechanism=SCRAM-SHA-256&authSource=admin"]

  # Optional SSL. By default is off.
  #ssl.enabled: true

  # Mode of verification of server certificate ('none' or 'full')
  #ssl.verification_mode: 'full'

  # List of root certificates for TLS server verifications
  #ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]

  # Certificate for SSL client authentication
  #ssl.certificate: "/etc/pki/client/cert.pem"

  # Client Certificate Key
  #ssl.key: "/etc/pki/client/cert.key"

  # Username to use when connecting to MongoDB. Empty by default.
  username: myuser

  # Password to use when connecting to MongoDB. Empty by default.
  password: mypassword
~

```

As you can see i have tried quiet a few option but only first one works. Also i found this [MongoDB metricsets incorrectly handling multiple hosts · Issue #32188 · elastic/beats · GitHub](https://github.com/elastic/beats/issues/32188)

---

<div class="post-metadata">

**Author:** ![rajsolanki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rajsolanki/32/86859_2.png) [@rajsolanki](https://discuss.elastic.co/u/rajsolanki)\
**Post date:** [August 3, 2022, 2:57pm UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912/4 "2022-08-03T14:57:11Z")

</div>

I have also opened a case with elastic support for 10 days and no movement on it ☹

---

<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:** [August 31, 2022, 4:57pm UTC](https://discuss.elastic.co/t/metricbeat-8-3-2-and-mongo-v5/309912/5 "2022-08-31T16:57:58Z")

</div>

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