For more instructions, check out https://docs.mongodb.com/master/administration/install-community/.
brew install mongodbsudo apt-get update
sudo apt-get install mongodbmongodNow to use Mongo in your Vapor project.
Add the package to your Package.swift.
.Package(url: "https://github.com/vapor/mongo-provider.git", majorVersion: 2)Add the provider to your Droplet.
import Vapor
import MongoProvider
let drop = Droplet()
try drop.addProvider(MongoProvider.Provider.self)And configure Fluent to use MongoDB by changing the key "driver" to be "mongo" inside `Config/fluent.json
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
{
"url": "mongodb://<db-user>:<db-password>@<host>:<port>/<database>"
}Note:
portandhostare optional.
You can also manually configure the provider in code. This will bypass the configuration files.
import Vapor
import MongoProvider
let drop = Droplet()
let mongo = try MongoProvider.Provider(database: ..., user: ..., password: ...)
drop.addProvider(mongo)Visit the Vapor web framework's documentation for more instructions on how to use this package.
Join the welcoming community of fellow Vapor developers in slack.
This package has been tested on macOS and Ubuntu.