Setting Up MongoDB



MongoDB is a scalable, high-performance, open source NoSQL database.

MongoDB’s most common features

  • Document-Oriented Storage - JSON-style documents with dynamic schemas offer simplicity and power.
  • Full Index Support - Index on any attribute, just like you’re used to.
  • Querying - Rich, document-based queries.

In addition, MongoDB has many scalability features such as:

  • Replication
  • Auto-sharding
  • Map/Reduce
  • GridFS

Installing MongoDB on a Cloud9 workspace

To install MongoDB in your workspace, you can open a terminal and run the following command:

sudo apt-get install -y mongodb-org

Running MongoDB on a Cloud9 workspace

MongoDB is preinstalled in your workspace. To run MongoDB, run the following below (passing the correct parameters to it). Mongodb data will be stored in the folder data.

$ mkdir data
$ echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$@"' > mongod
$ chmod a+x mongod

You can start mongodb by running the mongod script on your project root:

$ ./mongod

MongoDB parameters used:

--dbpath=data - Because it defaults to /var/db (which isn’t accessible)
--nojournal - Because mongodb usually pre-allocates 2 GB journal file (which exceeds Cloud9 disk space quota)
--bind_ip=$IP - Because you can’t bind to
--rest - Runs on default port 28017


You should use the host $IP instead of localhost as your driver connection URL. For example, in Node, it is: process.env.IP

MongoDB has drivers for all supported runtimes. Following are the most commonly used drivers:

Node.JS apps

Shell Access

To access a shell prompt for the above MongoDB run the following.

$ mongo

Check out for details on how to use the shell

Cant start MongoDB in C9
Mongo DB troubles
Mongod setup issue on Node install
NPM install mongodb breaks
How to connect mongodb with nodejs on Cloud9?
Command not found Mongo DB Connection
Error while installing and running mongod
Dont understand, how to run MongoDB in my workspace
App server not being able to connect to mongodb anymore
Can't install MongoDB
Tutorials - Table of Contents
Dont understand, how to run MongoDB in my workspace
MongoDB availability in nodes.js
MongoDB?! Error 502 - bad gateway
Error parsing command line: unknown option small try 'mongod --help' for more information
Mongod won't load - I'm going crazy!
How do I run mongod in my workspace?
Mongod Wont start. Filespace?

3 posts were split to a new topic: Errors on running Mongo


3 posts were split to a new topic: NPM install mongodb breaks


A post was split to a new topic: 404 when connecting to Mongo collection


I need to use mLab rather than installing mongo directly into my workspace. Could you provide info on this. I am just not figuring it out in a timely fashion.



Also would like to know if possible to use mongo 3 and, if so, how to set that up.

Thanks again!


I followed the instructions here to install the latest version of MongoDB (3.2.7) in my Cloud9 workspace:


The --rest parameter actually brings up a HTTP REST interface. The current text kind of implies that it makes MongoDB listen at port 28017, but it actually listens for Mongo client connections at port 27017, while exposes the data over HTTP at port 28017.

I believe the text should be clearer on that, if there is any reason to use --rest at all.
Also, --httpinterface and --rest are considered deprecated in MongoDB 3.2 and will be removed in later releases (see )


I have followed the instructions above, but when running the mogod script I get the error:

2016-10-05T13:40:34.485+0000 [initandlisten] ERROR: Insufficient free space for journal files
2016-10-05T13:40:34.485+0000 [initandlisten] Please make at least 3379MB available in /data/db/journal or use --smallfiles

I have followed the instructions to the letter, my script contains:

mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$@"`

Not sure where I have gone wrong…


Please add the --smallfiles option to the command, and try again


Hi dannytech
I have added that flag and still see the same thing:

2016-10-06T10:14:05.049+0000 [initandlisten] ERROR: Insufficient free space for journal files
2016-10-06T10:14:05.049+0000 [initandlisten] Please make at least 3379MB available in /data/db/journal or use --smallfiles

Script is now:

mongod --bind_ip=$IP --dbpath=data --nojournal --smallfiles --rest "$@"


Is that all of the error or is there more?

2016-10-06T10:14:05.043+0000 [initandlisten] MongoDB starting : pid=2117 port=27017 dbpath=/data/db 64-bit host=ian_abbott-mongodb-test-3857581
2016-10-06T10:14:05.043+0000 [initandlisten] db version v2.6.12
2016-10-06T10:14:05.043+0000 [initandlisten] git version: d73c92b1c85703828b55c2916a5dd4ad46535f6a
2016-10-06T10:14:05.043+0000 [initandlisten] build info: Linux 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-10-06T10:14:05.043+0000 [initandlisten] allocator: tcmalloc
2016-10-06T10:14:05.043+0000 [initandlisten] options: {}
2016-10-06T10:14:05.049+0000 [initandlisten] journal dir=/data/db/journal
2016-10-06T10:14:05.049+0000 [initandlisten] recover : no journal files present, no recovery needed
2016-10-06T10:14:05.049+0000 [initandlisten] 
2016-10-06T10:14:05.049+0000 [initandlisten] ERROR: Insufficient free space for journal files
2016-10-06T10:14:05.049+0000 [initandlisten] Please make at least 3379MB available in /data/db/journal or use --smallfiles
2016-10-06T10:14:05.049+0000 [initandlisten] 
2016-10-06T10:14:05.049+0000 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating

The script is exactly as it is in my previous reply, including the option --smallfiles

to run the script i am right clicking and choosing Run


HI, same error here!

I’ve installed MongoDB on a free workspace following the above instructions. When running the mongod script I receive the below error:

ERROR: Insufficient free space for journal files
Please make at least 3379MB available in /data/db/journal or use --smallfiles

This is strange as my script includes the -nojournal option

Any suggestion?


@ian_abbott can you try running it from the command line, and for both of you, what is your current disk quota. If nothing you try works, could you try posting your workspaces here and a Cloud9 employee like @harutyun, @timjrobinson, or @bradydowling could take a quick look at it (or even myself)


Another good troubleshooting step is simply to download your workspace files and then upload them into a brand new workspace. If this helps then you’ve likely filled up your disk space with log, config, or other files that you probably don’t need.


OK, so if I run it from the console (ian_abbott:~/workspace $ ./mongod) then it works as it should:

2016-10-10T09:26:58.678+0000 [initandlisten] allocator: tcmalloc
2016-10-10T09:26:58.678+0000 [initandlisten] options: { net: { bindIp: "", http: { RESTInterfaceEnabled: true, enabled: true } }, storage: { dbPath: "data", journal: { enabled: false }, smallFiles: true } }

But if I run it by right-click and Run, it ignores all the options set in the file:

2016-10-10T09:27:13.219+0000 [initandlisten] allocator: tcmalloc
2016-10-10T09:27:13.220+0000 [initandlisten] options: {}

So for me, to get it to work I will run it from the console for now

Thanks for the help to find a resolution


Hi everyone,
the MongoDB version installed with this procedure is the v2.6.12
Is it possible to upgrade to 3.2 or does this generates issues?


When I did it, I installed 3.2 with no problems


Yes, you’re right. Upgraded to 3.2.10 and works perfectly. Thank you!