> ## Documentation Index
> Fetch the complete documentation index at: https://llm-tools.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

[MongoDB](https://www.mongodb.com/products/platform/atlas-vector-search) is an open source document database.
The company behind the open source product offers a managed cloud product **MongoDB Atlas**.
As of right now, only the Atlas version supports vector search while the open source version does not.

To use MongoDB as your vector database, follow these steps -

* Sign up for a MongoDB Atlas account if you haven't already. Once you have signed up, you will need to spin up a new cluster (or use an existing one)

<Note>
  You will need to provision a M10 (or higher) instance type to use Atlas vector search. Cheaper instance types or the free version (M0) give an error when vector indexes are created programatically.
</Note>

* The cluster creation takes a few minutes. Once the cluster is ready, click on the connect button on the dashboard to get the connection string.

<Note>
  You will need to add users separately and allow IP access from your relevant development and production environments.
</Note>

## Install MongoDB addon

```bash theme={null}
npm install @llm-tools/embedjs-mongodb
```

## Usage

<CodeGroup>
  ```ts Example theme={null}
  import { RAGApplicationBuilder } from '@llm-tools/embedjs';
  import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';
  import { MongoDb } from '@llm-tools/embedjs-mongodb';
  import { WebLoader } from '@llm-tools/embedjs-loader-web';

  // set OPENAI_API_KEY in your env
  process.env.OPENAI_API_KEY = "sk-xxx";

  const app = await new RAGApplicationBuilder()
  .setEmbeddingModel(new OpenAiEmbeddings())
  .setModel(SIMPLE_MODELS.OPENAI_GPT4_O)
  .setVectorDatabase(new MongoDb({
      connectionString: 'mongodb+srv://<username>:<password>@<url>',
  })),
  .build();

  //add data source and start query it
  await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));
  await app.query('Tell me about Elon Musk');
  ```
</CodeGroup>

<Snippet file="missing-vector-db-tip.mdx" />
