https://github.com/vapor-community/mongo-provider
MongoDB Provider for Vapor
https://github.com/vapor-community/mongo-provider
cache database mongo swift vapor vapor-provider
Last synced: about 2 months ago
JSON representation
MongoDB Provider for Vapor
- Host: GitHub
- URL: https://github.com/vapor-community/mongo-provider
- Owner: vapor-community
- Created: 2016-09-24T06:05:11.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-08T19:38:09.000Z (over 7 years ago)
- Last Synced: 2025-04-29T09:56:10.819Z (6 months ago)
- Topics: cache, database, mongo, swift, vapor, vapor-provider
- Language: Swift
- Size: 21.5 KB
- Stars: 40
- Watchers: 9
- Forks: 18
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![]()
# Mongo Provider

[](https://circleci.com/gh/vapor-community/mongo-provider)
[](http://vapor.team)## ⬇ Install the MongoDB server
### OS X
For more instructions, check out https://docs.mongodb.com/master/administration/install-community/.
```shell
brew install mongodb
```### Linux
```shell
sudo apt-get update
sudo apt-get install mongodb
```### Run the server
```shell
mongod
```## 📦 Add Provider
Now to use Mongo in your Vapor project.
### Package
Add the package to your `Package.swift`.
```swift
.Package(url: "https://github.com/vapor/mongo-provider.git", majorVersion: 2)
```### Droplet
Add the provider to your Droplet.
```swift
import Vapor
import MongoProviderlet 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
### 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`
```json
{
"url": "mongodb://:@:/"
}
```> Note: `port` and `host` are optional.
### Manual
You can also manually configure the provider in code. This will bypass the configuration files.
```swift
import Vapor
import MongoProviderlet drop = Droplet()
let mongo = try MongoProvider.Provider(database: ..., user: ..., password: ...)
drop.addProvider(mongo)
```## 📖 Documentation
Visit the Vapor web framework's [documentation](http://docs.vapor.codes) for more instructions on how to use this package.
## 💧 Community
Join the welcoming community of fellow Vapor developers in [slack](http://vapor.team).
## 🔧 Compatibility
This package has been tested on macOS and Ubuntu.