# Providing a MongoDB Connection

{% hint style="info" %}
To **setup** a MongoDB database, you will need to **create a MongoDB Atlas Database** in the Cloud. Unless you already have a local/cloud database, please follow these [steps](https://www.mongodb.com/basics/mongodb-atlas-tutorial).
{% endhint %}

Once you get your connection string, **paste it** into `mongoDB.uri` option in the NoCliHandler instance. If you are using your local MongoDB database, I recommend you to use this type of connection string:

```bash
# With username and password
mongodb://<username>:<password>@localhost/<database_name>
# Without username and password
mongodb://localhost/<database_name>
```

{% hint style="warning" %}
It is **recommended** for you to store your connection string in an **environment file** when you are going to share your code. This is because hackers can **hijack your database** and mess around with it.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}
{% code title="index.js" %}

```javascript
// Library Imports
const { Client, IntentsBitField, Partials, version } = require('discord.js');
const NoCliHandler = require('nocli-handler.js').default;
const path = require('path');

// Setting Up Client Object
const client = new Client({
    // These intents are recommended for nocli-handler.js to handle commands
    intents: [
        IntentsBitField.Flags.Guilds,
        IntentsBitField.Flags.GuildMessages,
        IntentsBitField.Flags.GuildMessageReactions,
        IntentsBitField.Flags.DirectMessages,
        IntentsBitField.Flags.MessageContent,
        IntentsBitField.Flags.GuildMessageTyping
    ],
    partials: [Partials.Channel, Partials.Message]
});

client.on("ready", () => {
    const instance = new NoCliHandler({
        client,
        mongoDB: {
            uri: '<paste your connection string here>'
        },
        configuration: {
            defaultPrefix: "", // Current: !
            commandsDir: path.join(__dirname, 'commands'),
        },
        // clientVersion is required so that nocli-handler.js can help check
        // if you are on the right version as the handler
        language: "JavaScript"
    });
});
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="index.ts" %}

```typescript
// Library Imports
import { Client, IntentsBitField, Partials, version } from 'discord.js';
import NoCliHandler from 'nocli-handler.js';
import path from 'path';

// Setting Up Client Object
const client = new Client({
    // These intents are recommended for nocli-handler.js to handle commands
    intents: [
        IntentsBitField.Flags.Guilds,
        IntentsBitField.Flags.GuildMessages,
        IntentsBitField.Flags.GuildMessageReactions,
        IntentsBitField.Flags.DirectMessages,
        IntentsBitField.Flags.MessageContent,
        IntentsBitField.Flags.GuildMessageTyping
    ],
    partials: [Partials.Channel, Partials.Message]
});

client.on("ready", () => {
    const instance = new NoCliHandler({
        client,
        configuration: {
            defaultPrefix: "", // Current: !
            commandsDir: path.join(__dirname, 'commands'),
        },
        mongoDB: {
            uri: '<paste your connection string here>'
        },
        // clientVersion is required so that nocli-handler.js can help check
        // if you are on the right version as the handler
        clientVersion: version,
        language: "JavaScript",
        botOwners: ['your_discord_id']
    });
});
```

{% endcode %}

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tribui141108.gitbook.io/nocli-handler.js/guides/instance/providing-a-mongodb-connection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
