# Implementing extension with MongoDB database driver

**URL:** <https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589>\
**Category:** Uncategorized\
**Created:** [June 16, 2021, 9:19am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589 "2021-06-16T09:19:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.hivemq.com/u/Harsha)\
**Post date:** [June 16, 2021, 9:19am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/1 "2021-06-16T09:19:41Z")

</div>

Hi,

I am using the steps provided in the following link to implement a simple extension to intercept clientId, topics names, and message’s and log them to a MongoDB.

[https://www.hivemq.com/docs/hivemq/4.4/extensions/introduction.html](https://www.hivemq.com/docs/hivemq/4.4/extensions/introduction.html)

I am runnin the following command which generates the required file’s…

mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.4.8

…But I do not know how to include the MongoDB driver in the command.

Request you to help.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![YannickWeber](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yannickweber/32/103_2.png) [@YannickWeber](https://community.hivemq.com/u/YannickWeber)\
**Post date:** [June 23, 2021, 7:57am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/2 "2021-06-23T07:57:02Z")

</div>

Hello Harsha,

you can not include the version of the MongoDB database driver in the command. But you can add the mongoDB driver manually to the `pom.xml` once the project is created with the command.

Step 1: Create the Project with the command

```auto
mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.4.8

```

Step 2: Add your MongoDB driver dependency to the generated `pom.xml`:

```auto
<project>
   ...
    <dependencies>
        <dependency>
            <groupId>com.hivemq</groupId>
            <artifactId>hivemq-extension-sdk</artifactId>
            <version>4.4.8</version>
        </dependency>
       <dependency>
           <groupId>org.mongodb</groupId>
           <artifactId>mongodb-driver</artifactId>
           <version>3.12.8</version>
       </dependency>
    </dependencies>
   ....
</project>

```

Regards,  
Yannick

---

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.hivemq.com/u/Harsha)\
**Post date:** [June 24, 2021, 9:22am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/3 "2021-06-24T09:22:48Z")

</div>

Thank you Yannick.

Sorry I am new to this. Is there any command I need to run after modifying the pom.xml to actually install the drivers ?

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![YannickWeber](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yannickweber/32/103_2.png) [@YannickWeber](https://community.hivemq.com/u/YannickWeber)\
**Post date:** [June 24, 2021, 12:56pm UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/4 "2021-06-24T12:56:17Z")

</div>

Hello Harsha,

Running `mvn compile` should download all declared dependencies.  
See: [Maven – Introduction to the Build Lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html)

Regards,  
Yannick

---

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.hivemq.com/u/Harsha)\
**Post date:** [June 25, 2021, 6:24am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/5 "2021-06-25T06:24:32Z")

</div>

Thank you Yannick.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://community.hivemq.com/u/Harsha)\
**Post date:** [July 14, 2021, 10:47am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/6 "2021-07-14T10:47:10Z")

</div>

Hi,

I am using the hello word plugin to log published data to MongoDB. I am trying to find the syntax to get the client id and message payload. I am able to get the topic name in the “HelloWorldInterceptor.java” file which is created when I run the command

mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.6.3 -DhivemqExtensionSdkVersion=4.4.9

System.out.println(publishPacket.getTopic())

Also how do I locate API’s if I need to make more modification’s ? I am new to Java and have basic understanding of OOP concepts.

Regards,  
Harsha

---

<div class="post-metadata">

**Author:** ![michael\_w](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/michael_w/32/200_2.png) [@michael\_w](https://community.hivemq.com/u/michael_w)\
**Post date:** [July 15, 2021, 7:47am UTC](https://community.hivemq.com/t/implementing-extension-with-mongodb-database-driver/589/7 "2021-07-15T07:47:17Z")

</div>

Answered here: [Need help with HiveMQ SDK API's](https://community.hivemq.com/t/need-help-with-hivemq-sdk-apis/640)
