Wiki
Clone wikiieeg / MongoDBGuide
Using MongoDB as a local, unshared cache
Mac OS X
Get it from here:
http://www.mongodb.org/downloads
do this:
sudo mkdir -p /data/db sudo chown `id -u` /data/db
run it:
[install-location]/bin/mongod
Windows
Get it from here:
http://www.mongodb.org/downloads
If required, use the following command in the Command Prompt to find the architecture of your version of Windows platform:
wmic os get osarchitecture
If you are running any edition of Windows Server 2008 R2 or Windows 7, install the hotfix (http://support.microsoft.com/kb/2731284) to resolve an issue with memory mapped files on Windows.
Extract the downloaded archive to C:\ and start the Command Prompt by selecting the Start Menu-->All Programs-->Accessories then right click Command Prompt, and select Run as Administrator from the popup menu. do this:
cd \ move C:\mongodb-win32-* C:\mongodb
Create the default data folder:
md data md data\db
MongoDB is self-contained and does not have any other system dependencies. You can install MongoDB in any directory (e.g. D:\test\mongodb). You can also specify an alternate path for the data folder, using the following command
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
run it:
[install-location]\bin\mongod.exe
Having MongoDB Start at Boot Time
There doesn't look to be any official instructions, maybe try something from here out.
Or start it manually.
Set up the collection that will store the data
Maybe you want to limit the amount of space that MongoDB will use. (Heads up: MongoDB allocates all of the space from your disk immediately, which will take a while. Observe your mongod
window to see progress.)
Here's how you can limit to 10GB:
Fire up mongo and do this:
> use ieeg; > db.createCollection("mefBlocks", {capped:true, size:10740000000});
If you've already started to use MongoDB without setting a cap on the collection (i.e., you haven't already run the previos code snippet), you can convert an existing collection to capped:
> use ieeg; > db.runCommand({"convertToCapped": "mefBlocks", size: 10740000000}); > db.repairDatabase();
That last part is to reclaim space that was used up by the original, uncapped collection.
If you want to expand a capped collection, try something from here.
Here's documentation on capped collections.
Configure the Matlab Client to Use MongoDB
In the base of the unzipped matlab toolbox, you'll find a file called tsi.properties.example
. You will need to copy this file to a directory in your matlab path and rename it to tsi.properties
. We recommend keeping this file in your default userpath
directory, but in any case it should be kept outside of the exploded zip directory of the toolbox so that it is not lost when you update your toolbox installation. Once you have the file in place uncomment the mongodb.hostname
line. You will also need to uncomment and modify the mongodb.port
line if you chose to have MongoDB listen on a non-default port. The mongodb.username
and mongodb.password
lines should remain commented out unless you are running a MongoDB server with auth
turned on as described in the next section.
#mongodb.hostname=localhost #mongodb.port=27017 #mongodb.username= #mongodb.password=
That should be pretty much it if you just want to cache data on your PC. But maybe you want to set up a shared instance in your lab so you all can access data from your local network.
Running a shared MongoDB server
Security Considerations
If you decide to run a shared MongoDB server for your lab, then you should read http://docs.mongodb.org/manual/security/ to see recommendations on configuring MongoDB and your firewall.
Keep in mind that any user that is able to read from the MongoDB ieeg database will have access to all the data currently stored there. So if your lab uses datasets which not all members of the lab should be able to access, then using a shared MongoDB server represents a security hole and should not be used. The IEEG Toolbox MongoDB client supports username/password authentication if your server is running with the auth setting. But this can only restrict access at the database level and not prevent a user from seeing particular items.
Another consideration is that the downloads of MongoDB at http://www.mongodb.org/downloads do not support SSL. All data, including MongoDB usernames and passwords are sent in the clear, so it is imperative that your MongoDB server is only accessible on a trusted network. You can build from the source code or purchase MongoDB enterprise to enable SSL support. See http://docs.mongodb.org/manual/tutorial/configure-ssl.
Setup for Authentication Notes
You may want to run your server with the auth
option turned on so that a username and password are required to access MongoDB. If so, the instructions to get you started are at http://docs.mongodb.org/manual/tutorial/enable-authentication/. But here is a summary:
- You will have to add the line
auth = true
to your MongoDB configuration file since auth
is disabled by default. Instructions on how to run mongod
with a config file can be found at http://docs.mongodb.org/manual/reference/configuration-options/ along with descriptions of the available options. The options related to security are also discussed in more detail at http://docs.mongodb.org/manual/administration/configuration/#configuration-security. If you used a package management system to install MongoDB it may have created a configuration file and init script for you. See the section of http://docs.mongodb.org/manual/installation/ for your OS for details.
- Connect to MongoDB shell from localhost and create an admin user. Allowed even with
auth
turned on because of localhost exception until admin user is created. Summary of http://docs.mongodb.org/manual/tutorial/add-user-administrator/ :
> db = db.getSiblingDB('admin') > db.addUser( { user: "<username>", pwd: "<password>", roles: [ "userAdminAnyDatabase" ] } )
- Exit shell and log back in to admin db using new user:
mongo -u <username> -p <password> admin
- Create a regular user with readWrite role on the ieeg database. The readWrite role allows drop and possibly other destructive commands. Summary of http://docs.mongodb.org/manual/tutorial/add-user-to-database/:
> use ieeg > db.addUser( { user: "<username>", pwd: "<password>", roles: [ "readWrite"] } )
Note: Once you log out of the MongoDB shell after step 2, the localhost exception is closed so that you will always have to specify a user, password, and database on the shell command line in the future. Unless you restart mongod without the auth
option.
- Uncomment and fill in the
mongodb.username
andmongodb.password
lines in yourtsi.properties
file.
Updated