Skip to content

mongodb/mongodb-vapor-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongodb-vapor-template

This repository contains a template which can be used for generating new projects using MongoDB and Vapor via MongoDBVapor with Vapor's command line tool, Vapor Toolbox:

vapor new MyProject --template https://github.com/mongodb/mongodb-vapor-template/

Getting Started

  1. Install Vapor Toolbox. Installation instructions can be found here for macOS and here for Linux.

  2. Initialize a new project from the command line, and move into the project directory:

vapor new MyProject --template https://github.com/mongodb/mongodb-vapor-template/
cd MyProject
  1. If you're using Linux The driver vendors and wraps the MongoDB C driver (libmongoc), which depends on a number of external C libraries when built in Linux environments. As a result, these libraries must be installed on your system in order to build the driver. To install those libraries, please follow the instructions from libmongoc's documentation.

  2. Set up a MongoDB deployment to connect to. You can install MongoDB, and (in a new terminal window) start up a standalone server locally (this will run on the default host/port, localhost:27017):

mongod --dbpath /data/path/here

Alternatively, you can use MongoDB Atlas to set up a fully managed MongoDB deployment in the cloud.

  1. If using Atlas, or a local host/port besides the default localhost:27017, set your MongoDB connection string via environment variable:
export MONGODB_URI='connection-string-here'
  1. Load some sample data into the database via the MongoDB shell:
mongo $MONGODB_URI home --eval "db.kittens.insert([{name:\"roscoe\",color:\"orange\", createdAt: new Date()},{name:\"chester\",color:\"tan\", createdAt: new Date()}])"

If using Atlas, you could also do this via Atlas Data Explorer.

  1. Build and run the application (this might take a while on the first time):
swift build
swift run
  1. If using Leaf, go to http://localhost:8080 to see your app in action and load a list of kittens! Else, you can run curl http://localhost:8080 to see the resulting JSON.

  2. To add a new kitten: if using Leaf, use the form at http://localhost:8080. Else, you can add new data via curl: curl -d "name=Bob&color=white" http://localhost:8080.

Resources:

Get in Touch

Notice any issues with this template, or have ideas for how to make it more useful? Feel free to open a pull request or GitHub issue, or reach out to us on the SWIFT Jira project.

Releases

No releases published

Packages

No packages published

Languages