Southern New Hampshire University**We aren't endorsed by this school
Course
CS 340
Subject
Computer Science
Date
Dec 18, 2024
Pages
6
Uploaded by sage101
Mikayla-Joy BothaCS-340 Client/Server DevelopmentOct 29, 20241-3 Assignment: Intro to MongoDBIn this assignment, you will verify your access to MongoDB by using the Linux shell prompt to access the mongo shell. You will be asked to run different administrative queries on a database of email documents, enron.json, which has been uploaded into Mongo for you. Follow the steps outlined below to complete these tasks.1.Begin by logging into the Virtual Lab (Apporto) and accessing the terminal application. Use the Mongo in Apporto (Virtual Lab) Tutorial PDF to help with this task.2.First, you must verify access to the environment by starting up MongoDB and the mongo shell. Open the terminal application, which will bring up the Linux shell prompt. Complete the following:
○Execute the mongo command to start the mongo shell. This will bring up the mongo shell prompt.○Take a screenshot of the whole terminal window to verify your presence in the mongo shell. All of your screenshots mustinclude your username, which is at the top of your terminal window.3.Tip: It is important to make sure that your screenshots are clear and large enough to be easily read. Refer to this Use Snipping Tool to Capture Screenshots guide for help with taking screenshots.4.You have been given a preloaded database containing email documents. Exit MongoDB and return to the Linux prompt. Using the database provided, execute the following administrative commands:Load the database by executing the following at the Linux command line in the terminal you opened:cd /usr/local/datasetsmongoimport --username="${MONGO_USER}" \--password="${MONGO_PASS}" --port=${MONGO_PORT} \--host=${MONGO_HOST} --db enron --collection emails \ --authenticationDatabase admin --drop ./enron.jsonNote: You must type in the previous commands because cutting and pasting will generate an incorrect characterfor quotation marks. The MongoDB instance set up in your Apporto virtual lab has an administrative user configured, and the four environment variables MONGO_USER, MONGO_PASS, MONGO_PORT, and MONGO_HOST are pre-configured in your environment. Each of these must be added to the mongoimport =command because the database is not running on the same machine that is running your virtual lab. The --drop
option allows you to run the command several times without worrying about duplicate information being loadedinto the database.Retrieve a document from the collection by executing the following commands in the mongo shell. Take a screenshot to verify your execution of these commands.show dbs#lists directory of databasesuse enron#this sets db to the enron database
show collections#lists directory of collectionsdb.emails.findOne()#retrieves a document from the emails collection
○Execute the command to find the size of a single documentof your choosing from the enrondatabase. -Using the command: Object.bsonsize(db.emails.findOne())○Execute the command to find the size of the collection of documents in the enron database. Refer back to the Two Ways to Get a Document’s Size in MongoDB article if you need help constructing this command. Take a screenshot to verify your execution of this command.