Setting up MongoDB
- 1 Create a MongoDB server account
- 2 Kick the tires
- 3 Importing data into MongoDB
- 4 Quit the MongoDB client
- 5 Helpful links
- 6 What links here
Create a MongoDB server account
In order to use MongoDB, you will need to initialize your database on the server. You only need to do this once.
Follow the following steps to set up your MongoDB account
- visit our department's MongoDB page and click the link to the MongoDB Manager:
- log in with your CIMS username and password
- you now have a MongoDB account up and running with the following credentials:
- Your MongoDB database name is the same as your CIMS username - make a note of this
- Your MongoDB username is the same as your CIMS username - make a note of this
- Your MongoDB password will be displayed on this page - make a note of this
Kick the tires
The following instructions will allow you to connect the running MongoDB server and try out the MongoDB client.
Log into the i6 web server
You should now be logged into your account on the i6.cims.nyu.edu web server.
Load the MongoDB environment module
At the i6 command prompt, run the following command to auto-configure your UNIX shell environment so that it can properly run MongoDB.
- This needs to be done only once for every i6 session.
module load mongodb-3.6
Run the MongoDB client
Assuming you have already loaded the MongoDB environment, at the i6 command prompt, run the following command to enter the mongo client:
mongo xxxxxx --host class-mongodb.cims.nyu.edu -u xxxxxx -p <enter your MongoDB password when prompted>
Where xxxxxx is your MongoDB username (same as your CIMS/i6 username).
You should now be running the MongoDB shell, which is connected to the class-mongodb.cims.nyu.edu database server.
Try issuing commands
MongoDB should respond with "4".
Show a list of databases
//note: on our class-mongodb server, the following command does not work... ignore it show dbs
Select a particular database:
Show a list of all collections in the current database:
Importing data into MongoDB
The mongoimport command will import data into a MongoDB collection. You can import data structured as either JSON or CSV files.
- on our MongoDB server, your_username and your_database_name are the same as your CIMS/i6 username.
- you must first have loaded the MongoDB environment
- run these commands from the *NIX shell prompt, not from the mongo client prompt
Here is a sample of importing a document that contains data in JSON format:
mongoimport --db your_database_name --collection your_collection_name --host class-mongodb.cims.nyu.edu --username your_username --password your_password --type json --file your_json_file_name
mongoimport --db your_database_name --collection your_collection_name --host class-mongodb.cims.nyu.edu --username your_username --password your_password --type csv --headerline --file your_csv_file_name
Note that using the --headerline option means that your CSV file must include the field names as the first line of the file.
Quit the MongoDB client
To quit the MongoDB client when you are finished, type CTRL+C or 'exit'.
- MongoDB's official Getting Started tutorial with an excellent example data set, instructions for how to import that data, and examples of CRUD queries you can run on it once you have it imported.
- NYU CS's MongoDB server information
- NYU CS's MongoDB Manager
- NYU CS's i6 web server information
- Official MongoDB Documentation