/mongo-provider

MongoDB Provider for Vapor

Primary LanguageSwift

Mongo

Mongo Provider

Swift CircleCI Slack Status

⬇ Install Mongo

OS X

brew install mongo

Linux

sudo apt-get update
sudo apt-get install mongo

Run

mongod

📦 Add Provider

Now to use Mongo in your Vapor project.

Package

Add the package to your Package.swift.

.Package(url: "https://github.com/vapor/mongo-provider.git", majorVersion: 1, minor: 1)

Droplet

Add the provider to your Droplet.

import Vapor
import VaporMongo

let drop = Droplet()
try drop.addProvider(VaporMongo.Provider.self)

Note: If on Xcode you get a No such module ‘VaporMongo’ error, do a vapor xcode command. If that still doesn’t work do a vapor clean && vapor xcode command.

Config

Then add a mongo.json to your Config folder. You can add it in the root or keep it out of git in the secrets folder.

Config/
  - mongo.json
    secrets/
      - mongo.json

The secrets folder is under the .gitignore and shouldn't be committed.

Here's an example secrets/mongo.json

{
  "user": "username",
  "password": "badpassword",
  "database": "databasename",
  "port": "27017",
  "host": "z99a0.asdf8c8cx.us-east-1.rds.amazonaws.com"
}

Note: port and host are optional.

Manual

You can also manually configure the provider in code. This will bypass the configuration files.

import Vapor
import VaporMongo

let drop = Droplet()

let mongo = try VaporMongo.Provider(database: ..., user: ..., password: ...)
drop.addProvider(mongo)

📖 Documentation

Visit the Vapor web framework's documentation for more instructions on how to use this package.

💧 Community

Join the welcoming community of fellow Vapor developers in slack.

🔧 Compatibility

This package has been tested on macOS and Ubuntu.