---
title: "Get Connected to NoSQL Data Sources"
description: "Use MongoDB or DynamoDB as data sources for the Curity Identity Server"
url: "https://curity.io/resources/learn/using-nosql-data-sources/"
date: "2025-03-28"
area: "tutorials"
topic: "howtos"
pagegroup: "data-management"
---

# Get Connected to NoSQL Data Sources

This tutorial explains the basic steps to connect the Curity Identity Server to a NoSQL database, if, for example, you want to use managed database hosting from a cloud provider. The content describes some demo deployments. Once connected, you can plan your real database deployments.

## Get a Default Configuration

First, follow these getting started tutorials.

-   Get a license file, run an [Install using Docker](https://curity.io/resources/learn/run-curity-docker/) and sign into the Admin UI.
-   Run the [First Configuration](https://curity.io/resources/learn/first-config/), select `All Options` and accept all default settings.
-   [Export Configuration](https://curity.io/resources/learn/import-export-config/) so that you have a `curity-config.xml` file.

## Get Schema Initialization Scripts

Get the schema initialization script from the `$IDSVR_HOME/etc` folder of the Curity Identity Server. For example, you can run the following Docker commands.

```bash
docker pull curity.azurecr.io/curity/idsvr
docker run --name curity -d -e PASSWORD=Password1 curity.azurecr.io/curity/idsvr
docker cp curity:/opt/idsvr/etc/ ./etc/
docker rm --force curity
```

Study the resources that initialize NoSQL databases.

```text
mongo-create_database.js
dynamodb/*.json
```

## Deploy the System

The following examples demonstrate simple ways to get connected. You can configure data source details in the Admin UI by navigating to **Facilities** → **Data Sources**. The following sections instead demonstrate the XML configuration settings, so that you can plan rollouts to deployment pipelines.

**MongoDB**

Edit the `curity-config.xml` file and change the data source to configure a MongoDB connection.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
    <data-sources>
      <data-source>
        <id>default-datasource</id>
        <mongodb xmlns="https://curity.se/ns/ext-conf/mongodb">
          <password-credential>
            <password>Password1</password>
            <username>idsvruser</username>
          </password-credential>
          <connection-string>mongodb://dbserver:27017/idsvr</connection-string>
        </mongodb>
      </data-source>
    </data-sources>
...    
</facilities>
```

### Example Local Deployment

If you want to deploy a local development instance of MongoDB you could create the following `docker-compose.yml` file. This deployment also shares the MongoDB data to a `data` folder on the host computer. To deploy with clean data, delete any existing `data` folder on the host. Then run `docker compose up` to deploy the system.

```yaml
services:
  curity-data:
    image: mongodb/mongodb-community-server:latest
    hostname: dbserver
    container_name: dbserver
    volumes:
      - ./etc/mongo-create_database.js:/tmp/init.js
      - ./data:/data/db
    environment:
      MONGO_INITDB_ROOT_USERNAME: sa
      MONGO_INITDB_ROOT_PASSWORD: Password1
      MONGO_CURITY_USERNAME: idsvruser
      MONGO_CURITY_PASSWORD: Password1

  curity-idsvr:
    image: curity.azurecr.io/curity/idsvr:latest
    hostname: idsvr
    ports:
      - 6749:6749
      - 8443:8443
    volumes:
      - ./license.json:/opt/idsvr/etc/init/license/license.json
      - ./curity-config.xml:/opt/idsvr/etc/init/config.xml
    environment:
      ADMIN: 'true'
```

Once the system is running, get a shell to the Docker container for the database server.

```bash
docker exec -it dbserver bash
```

Then run the following command to create the database and initialize the schema.

```bash
mongosh dbserver:27017/idsvr -u sa -p Password1 --authenticationDatabase admin --file /tmp/init.js
```

Later, to query identity data, you can connect as the database user.

```bash
mongosh dbserver:27017/idsvr -u idsvruser -p Password1 --authenticationDatabase idsvr
```

Then run queries to access data such as user accounts.

```text
db.runCommand(
    {
        find: "accounts"
    }
)
```

**DynamoDB**

First use the DynamoDB JSON files to create each table. For example, you could use the [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and run the following commands:

```bash
for FILENAME in ./etc/DynamoDB/*.json; do
  aws dynamodb create-table --region eu-west-2 --cli-input-json "file://$FILENAME"
done
```

In the AWS console you can then see the created schema:

![DynamoDB Schema](https://curity.io/images/resources/howtos/data-sources/dynamodb-schema.jpg)

Next, edit the `curity-config.xml` file and change the data source to configure a DynamoDB connection with your preferred authentication method. The following example shows the configuration when you use an access key and secret. Other access methods are also possible, such as [IAM Roles for Service Accounts](https://curity.io/resources/learn/kubernetes-eks-dynamo-access-irsa/) for Kubernetes deployments.

```xml
<facilities xmlns="https://curity.se/ns/conf/base">
    <data-sources>
      <data-source>
        <id>default-datasource</id>
        <dynamodb xmlns="https://curity.se/ns/ext-conf/dynamodb">
          <aws-region>eu-west-2</aws-region>
          <access-key-id-and-secret>
            <access-key-id>AKIARJ6X ...</access-key-id>
            <access-key-secret>UoWTECOd ...</access-key-secret>
          </access-key-id-and-secret>
        </dynamodb>
      </data-source>
    </data-sources>
...    
</facilities>
```

Later, once you run flows that populate identity data, you can view data like account records in the AWS console.

![DynamoDB Data](https://curity.io/images/resources/howtos/data-sources/dynamodb-data.jpg)

## Finalize Configuration

Once connected, plan deployments to real environments that follow the provider's database best practices. Make sure that you use strong client credentials for database connections and encrypt data at rest. See the product documenation for details on the [System Requirements for Databases](https://curity.io/docs/identity-server/system-and-operation/deployment/system-requirements/#database) and the finer details for each [Data Source](https://curity.io/docs/identity-server/facilities/data-sources/overview/).

Finally, use the techniques in the [Configuration as Code](https://curity.io/resources/learn/gitops-configuration-management/) tutorial to finalize the database configuration for deployed systems. Use parameterized configuration and encrypt sensitive database values.

## Summary

The Curity Identity Server models data using abstractions so that it can store identity data in many data sources. You can therefore use NoSQL data sources to enable deployments such as managed data storage that your cloud platform provides.
