> ## Documentation Index
> Fetch the complete documentation index at: https://help.pixwel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Database

# Database

Data is stored in MongoDB via Mongo Atlas

Your local docker env will have a database called `pixwel-dev` pre-installed, but that's not super useful because it's not got real data in it.

## Getting real data into your development environment

Log into your mongo container `VERSION=latest docker-compose exec mongo bash` then run `cd utils`. In this directory you'll find two scripts to clone the staging or production database locally. You can run either `db-copy-prod-to-local.sh` or `db-copy-staging-to-local.sh`. Otherwise you can build your own custom script. The following template is given as example:

```bash theme={null}
#!/bin/bash
colls=( asset_types assets billingrates downloads_reportables email_jobs events fs.chunks fs.files groups imports offlines permissions permissions_cache previews projects shares studios subscriptions tags territories tokens translations users work_requests work_requests_reportables )

for c in ${colls[@]}
do
  mongodump --host <HOST> --db <DB> --port <PORT> --username <USERNAME> --password <PASSWORD> --collection $c
done

mv dump/<DB> dump/pixwel-dev

mongorestore --drop
```

You will need to supply values for `<DB>`, `<HOST>`, `<PORT>`, `<USERNAME>` and `<PASSWORD>`.

This will pull down the data, then pull the dump into your local mongodb.

Alternatively, you can sync a snapshot of the most recent 5,000 documents from each collection from any existing database using `api/_build/bin/mongo-sync.js`:

```bash theme={null}
mongo <host>:<port>/<database> -u <username> -p <password> api/_build/bin/mongo-sync.js
```

You'll then want to populate the search index. From the app container (`docker-compose exec app bash`):

```bash theme={null}
cd /var/www/api
li3 index-rebuild
```

## Running Migrations

Migrations, stored in [/api/\_build/migrations](https://github.com/Pixwel/platform/tree/2.x/api/_build/migrations), are not currently automated and should be run manually. Run a command like:

`mongo <host> <credentials> _build/migrations/<file>.js`

Please ensure your migrations are idempotent.

> TODO There is a command to [automatically flag deployments to master](https://github.com/radify/pixwel/pull/533) (not merged at the time of writing).

***

[Back to docs index](/) | [Next page in recommended reading order >>](/api/testing)
