Using MongoDB on i6.cims.nyu.edu

Using MongoDB on i6.cims.nyu.edu

Using Mongodb on i6.cims.nyu.edu

Note: We will cover all of this in class. In addition, please see your instructor or our TA with any questions!


Resources:


SETTING UP:

In order to set up, you will first need to set up a directory (or folder) to store your MongoDB data:

1. use TERMINAL on the Mac or PUTTY on Windows to log into i6.cims.nyu.edu using your netid and i6 password:

ssh i6.cims.nyu.edu -l <netid>
<enter your i6 password when prompted>

2. Once there … and at the prompt … type the following

$ mkdir -p ~/db/mongodb
$ chown <netid> ~/db/mongodb

for example: chown de123 ~/db/mongodb

Then modify your .bash_rc file by adding the following line:

$ pico ~/.bashrc

Add the following line and then use CTRL-X to save and exit:

module load mongodb-2.4.3

You only need to do these steps once.


TO USE MONGODB ON i6.cims.nyu.edu

1. use TERMINAL on the Mac or PUTTY on Windows to log into i6.cims.nyu.edu using your netid and i6 password

2. Run the MongoDB server:

$ mongod --dbpath ~/db/mongodb -port xxxx --smallfiles

xxxx: This is a 4-digit number to access a specific port. You might want to use for example the last 4 digits of your childhood phone number or other number and if it is already in use, increment by 1 until you succeed. Be sure to make a note of this port so that you can use it in further commands. Do not use a port number that starts with zero.

–smallfiles: This is important for the aggregation framework used in versions 2.2+. We will discuss this in class.

3. use TERMINAL on the Mac or PUTTY on Windowsto open a second window (or “shell”) and once again, log into i6.cims.nyu.edu using your netid and i6 password

4. Run MongoDB:

$ mongo -port xxxx

xxxx: This is a 4-digit number to access a specific port; be sure to use the same number as above.

5. If all went well, you are now ready to use MongoDB on i6 and you should see a prompt. For example, see if you can do addition:

> 2+2
4

IMPORTING DATA

You can use the mongoimport command at the Linux prompt to import data. Here is a sample:

mongoimport --db database-name --collection collection-name --type csv/json --file file-name --fieldFile fields-file -port xxxx

Note: You do not need the “fieldFile” information for data in the .json format.

FINISHING UP:

When you are done, complete the following steps to close out your MongoDB session:
1. In the shell that is running the MongoDB server,:
Use CTRL+D to stop the process and you will see “Bye“.
Type exit to close the Shell.

2. Then go to the shell where MongoDB is running.
Use CTRL+C to stop the process.
Type exit to close the Shell.