# Databases

Right now we are only supporting [Mongodb](https://www.mongodb.com/) out of the box. We are providing
an ORM via [Mongoose](http://mongoosejs.com/).

## Loading the module
Make sure that the ```mongodb``` module is loaded in the config file.
Also, make sure that the ```mongodb.url``` property is set in the config as below, and the
mongod instance is up and running.

```javascript
{
    // config/config.json

    // ...

    "modules": [
        // ...
        "mongodb"
        // ...
    ],

    // ...

    // MongoDB specific config
    // Currently only the url of the running mongod instance can be set.
    "mongodb": {
        "url": "mongodb://localhost"
    }
}
```

## Accessing the Database Connection
In any module:

```javascript
const registry = require('core/server/registry');
const database = registry.get('database:mongodb');
database.connection; // returns the current database connection instantiated by Mongoose
```

## Creating a new Mongoose Model
In any module:

```javascript
const registry = require('core/server/registry');
const database = registry.get('database:mongodb');
let model = database.model('Todo', {
    id: Number,
    name: String,
    description: String
});
```

## Make a model available throughout the codebase
In any module:

```javascript
const registry = require('core/server/registry');
const database = registry.get('database:mongodb');
let model = database.model('Todo', {
    id: Number,
    name: String,
    description: String
});

// add it to the registry
registry.add('database:model:Todos', model);
```

## Query

TBD

## Create

TBD

## Update

TBD

## Delete

TBD
