# MongoDb connection URI

**URL:** <https://community.graylog.org/t/mongodb-connection-uri/2663>\
**Category:** Development\
**Created:** [October 3, 2017, 8:53am UTC](https://community.graylog.org/t/mongodb-connection-uri/2663 "2017-10-03T08:53:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [October 3, 2017, 8:53am UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/1 "2017-10-03T08:53:22Z")

</div>

Hi,  
I need to save some data into Graylog MongoDB.  
Can someone help me to understand how to recover the its uri (as in cluster as in signle configuration)?

I know that is present a key **mongodb\_uri** on graylog.conf file, but I don’t know how to load it or if is present a default service to get it and its keys

Thanks

---

<div class="post-metadata">

**Author:** ![jochen](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/jochen/32/8_2.png) [@jochen](https://community.graylog.org/u/jochen)\
**Post date:** [October 3, 2017, 9:39am UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/2 "2017-10-03T09:39:01Z")

</div>

Please elaborate on what you want to achieve.

The credentials and connection details for MongoDB are configured in the `mongodb_uri` setting in the Graylog configuration file. So far so good, but I have no idea what you’re asking.

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [October 3, 2017, 9:56am UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/3 "2017-10-03T09:56:52Z")

</div>

Hi @jochen  
I try to explain what I want to do.  
In order to implement my custom input (JDBC), I need to save the index/timestamp that reached.  
So I thought to save them on Mongo (another collection I mean).

Here the idea to use the Greylog one.  
I noticed the Java class MongoDbConfiguration in the Graylog server project but I do not know whether it’s my case.

Have you some suggestions for me to solve my problem?

Thanks  
Gianluca

---

<div class="post-metadata">

**Author:** ![jochen](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/jochen/32/8_2.png) [@jochen](https://community.graylog.org/u/jochen)\
**Post date:** [October 3, 2017, 10:20am UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/4 "2017-10-03T10:20:07Z")

</div>

You can use [MongoJack](http://mongojack.org/) or use the [`PersistedImpl`](https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/database/PersistedServiceImpl.java) base class.

You can also inject [`MongoConnection`](https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/database/MongoConnection.java) in your class and work with the [MongoDB Java driver](https://mongodb.github.io/mongo-java-driver/) directly.

Examples:

- [https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/dashboards/DashboardServiceImpl.java](https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/dashboards/DashboardServiceImpl.java)
- [https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/grok/MongoDbGrokPatternService.java](https://github.com/Graylog2/graylog2-server/blob/2.3.1/graylog2-server/src/main/java/org/graylog2/grok/MongoDbGrokPatternService.java)

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [October 3, 2017, 1:25pm UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/5 "2017-10-03T13:25:08Z")

</div>

Thanks a lot,  
your solution is clear and efficient as always, by the way.

Gianluca

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/3X/c/7/c7c09c6b5099570133d6502b83f50ba4430de5b6.png) [@system](https://community.graylog.org/u/system)\
**Post date:** [October 17, 2017, 1:25pm UTC](https://community.graylog.org/t/mongodb-connection-uri/2663/6 "2017-10-17T13:25:09Z")

</div>

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