Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vapor-community/mongo-driver

MongoDB driver for Fluent
https://github.com/vapor-community/mongo-driver

fluent fluent-driver vapor

Last synced: 25 days ago
JSON representation

MongoDB driver for Fluent

Awesome Lists containing this project

README

        

# Mongo Driver for Fluent

![Swift](http://img.shields.io/badge/swift-3.1-brightgreen.svg)
[![Slack Status](http://vapor.team/badge.svg)](http://vapor.team)

## Install the MongoDB server

For more instructions, check out https://docs.mongodb.com/master/administration/install-community/.

### OS X

```shell
brew install mongodb
```

### Ubuntu

```shell
sudo apt-get update
sudo apt-get install mongodb
```

## Run the MongoDB server

```shell
mongod
```

## Connecting to MongoDB with Fluent

You need to edit `Config/fluent.json` to define mongo as the underlying database technology to use as driver for Fluent:

```json
{
"driver": "mongo"
}
```

Creating a driver is done using the [MongoDB Connection String URI Format](https://docs.mongodb.com/manual/reference/connection-string/). Initializing a `MongoDriver` such a URI will attempt a connection to MongoDB.

```swift
import MongoDriver
import Fluent

let driver = try MongoDriver("mongodb://localhost")
let db = Fluent.Database(driver)
```