Getting Started with Server-Side Swift Using the Vapor Web Framework

Continued from page 1. 

The first thing you'll need to do (in Terminal once again) is check to see whether you have everything you need to install Vapor, by executing the following command:

curl -sL | bash

If you are successful, you should see a one-liner, similar to the following:


To install everything you'll need, including dependencies, you can try running:

curl -sL | bash
Vapor Installation

You can test that Vapor was successfully installed, by typing

>vapor -help

afterward in terminal, and you should get a response, similar to the following:

Vapor Installation Test

If the Vapor command does return back the help commands, you're ready to create a new Vapor project, so in Terminal, continue by typing the following:

vapor new applestoreAPI
Create a new Vapor project

Installing MongoDB

If you don't already have MongoDB installed locally on your Mac or Linux-based development system, go ahead and install it by entering the following commands at the shell prompt:

$ brew install mongodb

Then, to start the MongolDB server, run:

brew services start mongodb
Start the MongolDB server

Creating the users and database in MongoDB

In Terminal, you're going to create a sample database within your MongoDB installation. The database will have records of three Apple Stores. To access the MongoDB console, enter the following:


Create a sample database within your MongoDB installation

The first thing you need to do is create a default user and password to access the database. Enter the following in your mongo console, to create (if it doesn't already exist) the stores document:

>use stores

> db.createUser(
...   {
...     user: "myTester",
...     pwd: "xyz123",
...     roles: [ { role: "readWrite", db: "stores"} ]
...   }
... )

The previous JSON document created a new user, myTester with read and write access to stores database. You can test that the new user has access by exiting the mongo console and typing:s

>mongo -u myTester  -p xyz123

If you have created the new user successfully, it should let you back into the mongo console with access to that database.

Doron Katz A keen passion for emerging technologies, practices and methodologies, Doron embraces the vision of lean development with continuous customer development. Consultant for various startups, as a Project and Product Manager, with a mobile engineering background in iOS, and over 10 years of professional web development experience.

Comments (2)


Hi , am able to successfully create the user but am not able to acces the console for stores db with the following command  >mongo -u myTester -p xyz123. I get this error  E QUERY    [main] SyntaxError: missing ; before statement @(shell):1:9

Am new to mongodb, any help appreciated. Thanks