In this question you create a new database named seneca and a collection student . We store
Question:
In this question you create a new database named seneca and a collection student. We store student data in this collection.
> use seneca
This command makes "seneca" your current database. However, the database will not be created until you insert a document into this database.
db.collection_name.insertOne({})
Insert a new document into your collection student with the following data:
first_name: Nick last_name: Adam email: &..m@email.com city: King status: part-time gpa: 3.6 program: BTD
Writte a command to check if the document has been created successfully.
You use find() method to search and fetch documents.
How many fields are in your document?
Is there any new field added to your document? (yes/no)
If yes, what is the name of the field?
Writte a command to remove the document that you created in Question 1. (We have only one document at this time, but when removing documents make sure you will not remove some other documents if not needed. So, make sure your command will remove "Nick Adam" from your collection. For now, we assume that we do not have duplicate names in our database.)
Note: To avoid making mistakes, you can first writte a find command with the proper criteria to see if the required document is fetched. Then, you can use the same criteria in your delete statement.
Writte the statement to remove "Nick Adam" from the database in the box below.
What is the message as a result of your delete statement in Question 3? Copy the message in the following box:
To see if the document that is removed successfully in Question 3, writte a search statement to see if the document exists or not. (We look for one document not all).
We want to add some students to our collection, but this time, we define the value for the _id field. (If the _id is not defined in your document, it will be added automatically.)
_id: 1001
first_name: Sarah last_name: Stone email: &..e@email.com city: Toronto status: full-time gpa: 3.4 program: CPA
_id: 1002
first_name: Jack last_name: Adam email: &..m@email.com city: North York status: part-time gpa: 3.6 program: CPA
To add these students, we want to store these documents into a variable first.
Define a variable named starray and add these two document to the variable. (You are storing more than one document so you need to define an array.)
Use the variable starray to add these two documents to your collection student.
Include both the variable declaration and the insert command in your answer.
What message is displayed after you execute the insert statement in Question 6. Copy the message in the answer box.
Writte a statement that shows all documents inserted in your collection student.
Writte a statement to remove all documents in the student collection.
Writte a statement to drop the database seneca in the answer box.
Before dropping a database, writte a command to make sure your current database is the one you want to delete. For this question, we want to delete (drop) the senecadatabase.
You can writte the use statement before removing the database to make sure your current database is seneca.
- use seneca
Or, you can writte the db or db.getName() statement to see the name of your current database:
- db
- db.getName()
If your current database is not seneca, writte the use statement to switch to seneca and then delete the database.
What message is displayed after you delete the database seneca in Question 10? Copy the message in the answer box.
Concepts of Database Management
ISBN: 978-1285427102
8th edition
Authors: Philip J. Pratt, Mary Z. Last