jjaybrown / mongo-provider

MongoDB Provider for Vapor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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: 0)

Droplet

Add the provider to your Droplet.

import Vapor
import VaporMongo

let drop = Droplet(providers: [VaporMongo.Provider.self])

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 mongo = VaporMongo.Provider(user: ..., password: ...)

let drop = Droplet(initializedProviders: [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.

About

MongoDB Provider for Vapor


Languages

Language:Swift 100.0%