+ All Categories
Home > Documents > MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase...

MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase...

Date post: 20-Aug-2019
Category:
Upload: hahanh
View: 213 times
Download: 0 times
Share this document with a friend
29
If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize and present your own logical solution to the problem. No lab is complete until the student submits the signed pledge form associated with that lab. I realize that no coded programs will be graded until I turn in the sign & pledge form associated with that program; any late penalties will continue to compound until the pledge form is submitted. If this lab is a team assignment, both team members may share logic as they program side by side on their own computers. Each person must type all of his/her own code as part of the learning process. Team assignments are never to be "You do this portion and I’ll do that portion" or "You do this lab and I’ll do the next lab" . Some of the lab assignments will have short answer questions. These short answer questions will be spot checked and graded for completion, but not checked for accuracy. Once these labs are graded and returned, I encourage you to compare answers with another class member who has also had the lab graded and returned. I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University. I realize that it is a violation of academic integrity to share any portion of this lab with any person (outside my 2320 team & professor)! Print Name _________________________________________ Time Required = ______.____ Hrs. Signature _______________________________________________________________ (pledged) MongoDB #2 Individual Assignment 30 Points Starting MongoDB Reeference Learn MongoDB http://www.tutorialspoint.com/mongodb Reference Learn MongoDB https://docs.mongodb.com/manual 1] __________________________________________________________________________________ MongoDB is a high performance D_?_ O_?_ Database. This does not mean that the only thing you can store in the database is Documents! 2] __________________________________________________________________________________ Assume that mongo is not installed as a service. Let us assume that you have opened a command/terminal window whose current directory is the bin directory in MongoDB. Write the line of code that you could use to launch the Mongo database server application. 3] _________ {T/F} Unless you install MongoDB as a service, you will have to go back to the bin directory and launch the database server application whenever you want to use Mongo. 4] __________________________________________________________________________________ Let us assume that MongoDB is running and that you have opened a second command/terminal window whose current directory is the bin directory in MongoDB. Write the line of code that you could use to start the Mongo. BSON Binary JSON 1] __________________________________________________________________________________ MongoDB stores data in the form of JSON-like_?_; these documents are analogous to Structures/Classes in programming languages that associate keys with values (e.g. dictionaries, hashes, maps, and associative arrays). 2] ___________ {T/F} Formally, MongoDB documents are BSON (binary representation of JSON ) documents with additional type information. In BSON documents, the value of a field can be any of the BSON data types, including other documents, arrays, and arrays of documents.
Transcript
Page 1: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize and present your own logical solution to the problem. No lab is complete until the student submits the signed pledge form associated with that lab. I realize that no coded programs will be graded until I turn in the sign & pledge form associated with that program; any late penalties will continue to compound until the pledge form is submitted. If this lab is a team assignment, both team members may share logic as they program side by side on their own computers. Each person must type all of his/her own code as part of the learning process. Team assignments are never to be "You do this portion and I’ll do that portion" or "You do this lab and I’ll do the next lab" . Some of the lab assignments will have short answer questions. These short answer questions will be spot checked and graded for completion, but not checked for accuracy. Once these labs are graded and returned, I encourage you to compare answers with another class member who has also had the lab graded and returned. I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University. I realize that it is a violation of academic integrity to share any portion of this lab with any person (outside my 2320 team & professor)!

Print Name _________________________________________ Time Required = ______.____ Hrs.

Signature _______________________________________________________________ (pledged)

MongoDB #2 Individual Assignment

30 Points

Starting MongoDB

Reeference Learn MongoDB

http://www.tutorialspoint.com/mongodb Reference Learn MongoDB

https://docs.mongodb.com/manual 1] __________________________________________________________________________________ MongoDB

is a high performance D_?_ O_?_ Database. This does not mean that the only thing you can store in the database is Documents!

2] __________________________________________________________________________________ Assume

that mongo is not installed as a service. Let us assume that you have opened a command/terminal window whose current directory is the bin directory in MongoDB. Write the line of code that you could use to launch the Mongo database server application.

3] _________ {T/F} Unless you install MongoDB as a service, you will have to go back to the bin directory and launch the database server application whenever you want to use Mongo.

4] __________________________________________________________________________________ Let us assume that MongoDB is running and that you have opened a second command/terminal window whose current directory is the bin directory in MongoDB. Write the line of code that you could use to start the Mongo.

BSON Binary JSON

1] __________________________________________________________________________________ MongoDB

stores data in the form of JSON-like_?_; these documents are analogous to Structures/Classes in programming languages that associate keys with values (e.g. dictionaries, hashes, maps, and associative arrays).

2] ___________ {T/F} Formally, MongoDB documents are BSON (binary representation of JSON ) documents with

additional type information. In BSON documents, the value of a field can be any of the BSON data types, including other documents, arrays, and arrays of documents.

Page 2: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 2 |

3] __________________________________________________________________________________ MongoDB data is stored using JSON-like value pairs; this format is called B_?_ format.

Collections

. 1] __________________________________________________________________________________ Within

each database, MongoDB stores all documents in C_?_. 2] __________________________________________________________________________________ Each

mongo C_?_ contains one, or more related documents that have a set of shared common indexes.

3] ___________ {T/F} Each document, within a collection, must have the same fields.

CRUD

1] __________________________________________________________________________________ CRUD is

an acronym for _?_.

2] __________________________________________________________________________________ BREAD is

an acronym for _?_. [Hint: "Browse, Read, Edit, Add, Delete" Not On Exam or Quiz] 3] __________________________________________________________________________________ MADS is

an acronym for _?_. [Hint: "Modify, All, Delete, Show" Not On Exam or Quiz]

EXECUTE ALL OF THE FOLLOWING QUERY REQUESTS

Be sure to execute All of the query requests in this lab.

Show The Databases

1] __________________________________________________________________________________ Write the

line of code that will list all of the Databases.

2] __________________________________________________________________________________ The two

databases, that are automatically installed with each and every new Mongo, are A_?_ and l_?_.

Page 3: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 3 |

Create A New Database use

1] __________________________________________________________________________________ Write the

line of code that will prepare to create a new database, called Trinity, and make it the default database. The

database is actually created with the first insert. 2] __________________________________________________________________________________ It is

sometimes the case that the database is not actually created until something is written to that database. Write the

line of code to add name: "Tom" to a collection called students. 3] _________ {T/F} When I execute the command "show dbs", I now see Trinity and local.

4] _________ {T/F} Suppose I return to MongoDB next week. I start the server. I open the command window. When

I execute the command "use Trinity", this makes Trinity my default database.

Add A New Record db.insert

1] __________________________________________________________________________________ It is

sometimes the case that the database is not actually created until something is written to that database. Write the

line of code to add name: "Dick" to a collection called students. 2] __________________________________________________________________________________ It is

sometimes the case that the database is not actually created until something is written to that database. Write the

line of code to add name: "Harry" to a collection called students. 3] You do not have to write the lines, but add "Ann", "Betty" & "Judy" to your database.

Show Collections

1] __________________________________________________________________________________ Write the line of code that will list all of the collections in the default database.

2] __________________________________________________________________________________ Write the

line of code that will make local the default database. 3] __________________________________________________________________________________ List at

least one of the collections in the local the default database.

Configuring The Mongo Prompt

1] __________________________________________________________________________________ The

Mongo prompt is _?_

Display Documents find()

Page 4: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 4 |

1] __________________________________________________________________________________ Write the

line of code that you could use to display all of the documents in the student collection.

2] __________________________________________________________________________________ If you

have entered only the documents specified in this lab, you will have _?_ documents in the student listing from student.find().

3] __________________________________________________________________________________ If you

have entered only the documents specified in this lab, each of the documents will have _?_ fields.

4] ___________________________________________________________________ In MongoDB, if you do not

have an object of ObjectID type, the database will automatically create one called _?_ ; it is the equivalent of a primary key in relational database. This makes each and every record unique.

Display Documents In Order find().sort

1] __________________________________________________________________________________ Write the

line of code that you could use to display all of the documents in the student collection in order by name.

2] __________________________________________________________________________________ Write the

line of code that you could use to display all of the documents in the student collection in order by _id.

Display A Partial Set Of The Documents find().limit

1] __________________________________________________________________________________ Write the

line of code that you could use to display the first three of the documents in the student collection in order by name.

2] __________________________________________________________________________________ Write the

line of code that you could use to display the first of the documents in the student collection in order by _id.

Delete A Collection drop() Collection

1] __________________________________________________________________________________ Write the

line of code that will prepare to create a new database, called Test, and make it the default database. The

database is actually created with the first insert. 2] __________________________________________________________________________________ Write the

line of code to add name: "Dick" to a collection called user.

3] __________________________________________________________________________________ Write the

line of code to delete the collection called User.

Single or Double Quotes?

db.user.insert({name: "Tom", office: "270Q CSI"})

Page 5: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 5 |

db.user.insert({name: 'Seth', office: '269Q CSI'}) 1] _________ {Y/N} Execute the two lines above. Does it appear that programmers have the choice of using either

single or double quotes to bound string data? Note that the ObjectID's will be different than mine.

Delete A Document remove() Document

1] __________________________________________________________________________________ Write the

line of code that will prepare to create a new database, called Trinity, and make it the default database. The

database is actually created with the first insert.

2] __________________________________________________________________________________ Write the

line of code to delete the User whose name is Tom.

3] __________________________________________________________________________________ Write the

line of code to delete all of the students.

Field Names Are Case Sensitive

db.user.remove({'Name': 'Seth'})

1] __________________________________________________________________________________ Execute the query above to remove Seth. Can you tell me why it did not remove Seth?

2] _________ {T/F} Case sensitivity does not matter when I am using a field name in a query.

String Matches Are Case Sensitive

db.user.remove({'name': 'seth'})

1] __________________________________________________________________________________ Execute

the query above to remove Seth. Can you tell me why it did not remove Seth?

2] _________ {T/F} Case sensitivity does matter when I am using a string in a query.

Create File Faculty.txt

Page 6: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 6 |

1] _____________________________________________________________________ {Sign/Pledge} I have created a file, called Faculty.txt, that contains the 8 data records seen below.

Create File Student.txt

1] _____________________________________________________________________ {Sign/Pledge} I have created a file, called Student.txt, that contains the 10 data records seen below.

Robo 3T

1] _________ {Y/N} Copy the first of the insertions from Faculty.txt to the clipboard. Try to paste it into the

command window running mongo. Were you successful? 2] _________ {Y/N} Start Robo 3T. Connect to your server. Were you successful creating the connection? If not,

do a YouTube search on Robo 3T. Robo 3T provides a free GUI entry into your Mongo database.

Page 7: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 7 |

3] _________ {Y/N} Using the mouse, open double click on the Trinity Database. Using the mouse, double click on Collections. Using the mouse, double click on the student collection. Note that the ObjectID's will be different than mine. Do you see some entries similar to that above?

pretty()

1] __________________________________________________________________________________ Write the

line of code that you could use to display all of the documents in the faculty collection – as illustrated above.

2] __________________________________________________________________________________ Write the

line of code that you could use to display all of the documents in the faculty collection in the pretty format shown

above. This is quite useful as the number of records increase.

Different Student Collection

1] __________________________________________________________________________________ Write the

line of code to delete the collection called Student.

limit()

Page 8: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 8 |

1] __________________________________________________________________________________ Write the

line of code that you could use to display the first 6 faculty documents in the pretty format shown above.

2] __________________________________________________________________________________ Write the

line of code that you could use to display the first 3 faculty documents in the pretty format shown above.

3] __________________________________________________________________________________ Write the

line of code that you could use to display the first 4 student documents.

4] __________________________________________________________________________________ Write the

line of code that you could use to display the first 2 student documents in the pretty format

sort()

1] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents in order by name as illustrated above.

Page 9: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 9 |

2] __________________________________________________________________________________ Write the

line of code that you could use to display the first six of the faculty documents in order by name. 3] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents in order by tuid. 4] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents in pretty format order by tuid. 5] __________________________________________________________________________________ Write the

line of code that you could use to display the first six of the faculty documents in the pretty format in order by

name.

6] __________________________________________________________________________________ Write the

line of code that you could use to display the first six of the student documents in the pretty format in order by

name.

7] __________________________________________________________________________________ Write the

line of code that you could use to display the first 10 of the student documents in the pretty format in order by

major.

8] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents in order by tenured but when the tenure

is the same order the data by name. Your results should resemble those below.

9] __________________________________________________________________________________ Write the

line of code that you could use to display all of the student documents in order by major but when the major is

the same order the data by name. Your results should resemble those below.

Page 10: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 10 |

find() Match A Single Field Equality

1] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents whose name is "Dr. Myers".

db.faculty.find({name: 'Dr. Lewis'}) 2] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'. db.faculty.find({'name': 'Dr. Lewis'}) 3] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'.

db.faculty.find({name: "Dr. Lewis"}) 4] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'.

db.faculty.find({"name": "Dr. Lewis"}) 5] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'.

db.faculty.find({'name': "Dr. Lewis"}) 6] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'. db.faculty.find({name: "Dr. Lewis'}) 7] _________ {T/F} The query above could be used to display all of the faculty documents whose name is 'Dr.

Lewis'. 8] __________________________________________________________________________________ Write the

line of code that you could use to display all of the faculty documents whose tuid is 100001.

db.faculty.find({tuid: '100002'})

9] _________ {T/F} The query above could be used to display all of the faculty documents whose trinity id is 100002.

10] __________________________________________________________________________________ Write the

line of code that you could use to display all of the tenured faculty documents in order by name. 11] __________________________________________________________________________________ Write the

line of code that you could use to display all of the tenured faculty documents in order by name. 12] __________________________________________________________________________________ Write the

line of code that you could use to display all of the Computer Science student documents in order by name.

Page 11: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 11 |

Start Watching This Presentation #1

Watch MongoDB Tutorial 1 What is MongoDB?

https://www.youtube.com/watch?v=liQzIsFnCr0 These homework questions can be answered as you watch the video. They are ordered with the content. There will be times when you should stop the video and do some web searching along the way. 1] ___________________________________________________________________ MongoDB is a high

performance D_?_ O_?_ Database.

2] ___________________________________________________________________ MongoDB is developed and supported by a company that was initially called 1_?_.

3] _________ {T/F} MongoDB is open source. 4] According to the presentation, there are three major database types. List them.

___________________________________________________________________ R_?_ ___________________________________________________________________ O_?_ ___________________________________________________________________ N_?_

5] ___________________________________________________________________ The problem that generated

the need for NOSQL was that Relational Databases could not handle B_?_D_?_ 6] ___________________________________________________________________ RDBMS systems are not

horizontally S_?_ 7] ___________________________________________________________________ Horizontal Scalability means

that you keep adding more and more _?_ as you need more power.

WHEN THE PRESENTATION STARTS TO DISCUSS BIGDATA STOP IT (FOR THE MOMENT)

Big Data

Stop the Presentation! Look up and read about “Big Data”. Start with Wikipedia. 1] ______________________________________________________________ Big data is a term for data sets that

are so L_?_ or complex that traditional data processing applications are inadequate. Challenges include analysis, capture, data curation, search, sharing, storage, transfer, visualization, querying, updating and information privacy.

2] ___________________________________________________________________ The term “Big Data” often

refers simply to the use of predictive An_?_ or certain other advanced methods to extract value from data, and seldom to a particular size of data set. Accuracy in big data may lead to more confident decision making, and better decisions can result in greater operational efficiency, cost reduction and reduced risk.

3] ___________________________________________________________________ Analysis of the data sets,

extracted from “Big Data”, can find new Correl_?_ to "spot business trends, prevent diseases, combat crime and so on.

Page 12: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 12 |

4] ___________________________________________________________________ Data sets are Gro_?_ rapidly in part because they are increasingly gathered by cheap and numerous information-sensing mobile devices, aerial (remote sensing), software logs, cameras, microphones, radio-frequency identification (RFID) readers and wireless sensor networks.

5] ___________________________________________________________________ According to research, the

world's technological per-capita capacity to store information has roughly Do_?_ every 40 months since the 1980s; as of 2012, every day 2.5 Exabytes (2.5×10^18) 2.5 Billion Gigabytes of data are created.

6] ___________________________________________________________________ Relational database

management systems and desktop statistics and visualization packages often have difficulty handling B_?_ D_?_. The work instead requires "massively parallel software running on tens, hundreds, or even thousands of servers".

7] _____________{T/F} What is considered "Big Data" varies depending on the capabilities of the users and their

tools, and expanding capabilities make big data a moving target. "For some organizations, facing hundreds of gigabytes of data for the first time may trigger a need to reconsider data management options. For others, it may take tens or hundreds of terabytes before data size becomes a significant consideration."

Key-Value NoSQL Databases

Look up and read about “Key-Value Database”. Start with Wikipedia.

1] ___________________________________________________________________ A key-value store, or key-value database, is a data storage paradigm designed for storing, retrieving, and managing associative arrays, a data structure more commonly known today as a D_?_ or hash.

2] ___________________________________________________________________ In key-valued databases, dictionaries contain a Col_?_ of objects, or records, which in turn have many different fields within them, each containing data. These records are stored and retrieved using a key that uniquely identifies the record, and is used to quickly find the data within the database.

3] ___________________________________________________________________ Key-value stores work in a very different fashion from the better known relational databases (RDB). RDBs pre-define the data structure in the database as a series of tables containing fields with well-defined data types. Exposing the data types to the database program allows it to apply a number of optimizations. In contrast, key-value systems treat the data as a single opaque collection which may have different fields for every Rec_?_. This offers considerable flexibility and more closely follows modern concepts like object-oriented programming. Because optional values are not represented by placeholders as in most RDBs, key-value stores often use far less memory to store the same database, which can lead to large performance gains in certain workloads.

4] Performance, a lack of standardization and other issues limited key-value systems to niche uses for many years,

but the rapid move to CL_?_ computing after 2010 has led to a renaissance as part of the broader NoSQL movement. Some graph databases are also key-value stores internally, adding the concept of the relationships (pointers) between records as a first class data type.

Page 13: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 13 |

Memcached Key-Value Store NoSQL

Look up and read about “Memcached”. Start with Wikipedia. Memcached is a “Key Value Store” NoSQL

Database. It is one of the solutions used to manage Big Data. 1] ___________________________________________________________________ Memcached is a general-

purpose distributed M_?_ C_?_ system. Memcached is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read.

2] ___________________________________________________________________ Memcached is Op_?_

So_?_ software, licensed under the Revised BSD license. 3] _______________________ __________________ _______________________ Memcached runs on L_?_ ,

OS_?_, Microsoft W_?_. It depends on the libevent library.

4] __________________________________________________________________ Memcached's APIs provide a very large H_?_ table distributed across multiple machines. When the table is full, subsequent inserts cause older data to be purged in least recently order. Applications using Memcached typically layer requests and additions into RAM before falling back on a slower backing store, such as a database.

5] __________________________________________________________________ The size of Memcached's

hash table is often very large. It is limited to available M_?_ across all the servers in the cluster of servers in a data center. Where high volume, wide audience web publishing requires it, this may stretch to many gigabytes. Memcached can be equally valuable for situations where either the number of requests for content is high, or the cost of generating a particular piece of content is high.

Redis Key-Value Store NoSQL

Look up and read about “Redis”. Start with Wikipedia. Redis is a “Key Value Store” NoSQL Database. 1] __________________________________________________________________ Redis is a data structure

server. It is open-source, networked, in-memory, and stores K_?_ with optional durability. The development of Redis has been sponsored by Redis Labs since June 2015. According to the monthly ranking by DB-Engines.com, Redis is the most popular key-value database.

2] __________________________________________________________________ The name Redis means

REmote D_?_ Server.

3] __________________________________________________________________ _?_ is an open source data structure server; it is the most popular key-value database.

Oracle Coherence Key-Value Store NoSQL

Look up and read about “Oracle Coherence”. Start with Wikipedia. Oracle Coherence is a “Key Value Store” NoSQL Database.

1] __________________________________________________________________ Oracle Coherence is a

proprietary Java-based in-memory data grid, designed to have better reliability, Sca_?_ and performance than traditional relational database management systems.

Page 14: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 14 |

2] __________________________________________________________________ Oracle’s C_?_ product, that they purchased Tangosol provides them with an entry into the NoSQL market.

3] __________________________________________________________________ _?_ is a proprietary Java-based in-memory data grid, designed to have better reliability, scalability and performance than traditional relational database management systems; Oracle purchased the product from Tangosol in order to move into the NoSQL market.

Riak Key-Value Store NoSQL

Look up and read about “Riak”. Start with Wikipedia. Riak is a “Key-Value Store" NoSQL Database.

1] __________________________________________________________________ Riak is a distributed NoSQL

key-value data store that offers high availability, fault tolerance, operational simplicity, and Sc_?_. Riak is written in Erlang.

2] __________________________________________________________________ In addition to the open-source version, Riak comes in a supported En_?_ version and a cloud storage version. Riak has fault tolerance data replication and automatic data distribution across the cluster for performance and resilience.

3] ___________________________________________________________________ Riak is Op_?_ So_?_ database that offers high availability, fault tolerance, simplicity, and scalability.

4] __________________________________________________________________ _?_ is a distributed NoSQL

key-value data store that offers high availability, fault tolerance, operational simplicity, and Scalability. It is written in Erlang and offers a free community version as well an enterprise version and a cloud storage version.

Bigtable Tabular NoSQL

Look up and read about “Bigtable”. Start with Wikipedia. Bigtable is a “Tabular” NoSQL Database. 1] ___________________________________________________________________ Bigtable is a compressed,

high performance, and proprietary data storage system built on G_?_ F_?_ S_?_ , Chubby Lock Service, SSTable (log-structured storage like LevelDB) and a few other Google technologies.

2] ___________________________________________________________________ Google's reasons for

developing its own Big Table database include Sc_?_ and better control of performance characteristics. 3] ___________________________________________________________________ _?_ is a proprietary,

tabular NoSQL database built on the Google File System.

Hbase Tabular NoSQL

Look up and read about “Apache Hbase”. Start with Wikipedia. Hbase is a “Tabular” NoSQL Database. 1] ___________________________________________________________________ Hbase is an open source,

non-relational, distributed database modeled after Google's Bigtable and written in Java. It is developed as part of A_?_ Software Foundation's Hadoop project and runs on top of HDFS (Hadoop Distributed Filesystem), providing Bigtable-like capabilities for Hadoop.

2] ___________________________________________________________________ Hbase is an Op_?_ So_?_,

non-relational, distributed database modeled after Google's Bigtable

Page 15: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 15 |

3] ___________________________________________________________________ Hbase provides Apache

with a fault-tolerant way of storing large quantities of Sp_?_ data (small amounts of information caught within a large collection of empty or unimportant data, such as finding the 50 largest items in a group of 2 billion records, or finding the non-zero items representing less than 0.1% of a huge collection).

4] ________ {T/F} Hbase is now serving several data-driven websites, including Facebook's Messaging Platform. As

of 2015, Hbase is the second most popular NoSQL Tabular Database First was Apache Cassandra. 5] ___________________________________________________________________ _?_ is An Apache Software

tabular NoSQL database that is modeled after Google's Bigtable; it is written in Java and used in the Hadoop project.

Accumulo Tabular NoSQL

Look up and read about “Apache Accumulo”. Start with Wikipedia. Accumulo is a “Tabular” NoSQL Database. 1] ___________________________________________________________________ Apache Accumulo is a

computer software project that developed a sorted, distributed key/value store based on the Bi_?_ technology from Google.

2] ________ {T/F} Apache Accumulo is a system built on top of Apache Hadoop, Apache ZooKeeper, and Apache

Thrift. Written in Java, Accumulo has cell-level access labels and server-side programming mechanisms. As of 2015, Accumulo is the third most popular NoSQL Tabular Database First and Second were Apache Cassandra and Apache Hbase.

Cassandra Key-Value Tabular Hybrid NoSQL

Look up and read about “Apache Cassandra”. Start with Wikipedia. Cassandra is a Hybrid Combining “Tabular” & "Key-Value Stores " NoSQL Database.

1] ___________________________________________________________________ Apache Cassandra is a free

and open-source distributed database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of Fa_?_. Cassandra offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication allowing low latency operations for all clients.

2] ___________________________________________________________________ Cassandra is an Op_?_ So_?_, non-relational, distributed database that is a hybrid between key-value stores and tabular NoSQL.

3] ___________________________________________________________________ Cassandra also places a

high value on performance. In 2012, University of Toronto researchers studying NoSQL systems concluded that "In terms of scalability, there is a clear winner throughout our experiments. Cassandra achieves the highest Throu_?_ for the maximum number of nodes in all experiments" although "this comes at the price of high write and read latencies."

4] ___________________________________________________________________ _?_ is essentially a hybrid between a key-value and a column-oriented (or tabular) database management system. Its data model is a partitioned row store with tunable consistency

Page 16: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 16 |

CouchDB Document Oriented NoSQL

Look up and read about “CouchDB”. Start with Wikipedia. CouchDB is a “Documented Oriented” NoSQL

Database. 1] ___________________________________________________________________ Apache CouchDB,

commonly referred to as CouchDB, is open source database software that focuses on ease of use and having an architecture that "completely embraces the W_?_"

2] ___________________________________________________________________ CouchDB is an Op_?_

So_?_ database software that focuses on ease of use and having an architecture that "completely embraces the Web"

3] ___________________________________________________________________ Unlike a relational

database, a CouchDB database does not store data and relationships in tables. Instead, each database is a collection of independent Do_?_.

4] ___________________________________________________________________ Each CouchDB document

maintains its own data and self-contained schema. An application may access multiple databases, such as one stored on a user's mobile phone and another on a server. Document metadata contains Rev_?_ information, making it possible to merge any differences that may have occurred while the databases were disconnected.

5] ___________________________________________________________________ is an Apache document-

oriented NoSQL database architecture and is implemented in the concurrency-oriented language Erlang; it uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API. Each document maintains its own data and self-contained schema

Cloudant Document Oriented NoSQL

Look up and read about “Cloudant”. Start with Wikipedia. Cloudant is a “Documented Oriented” NoSQL Database.

1] ___________________________________________________________________ Cloudant is an IB_?_

software product, which is primarily delivered as a cloud-based service. Cloudant is an open source NoSQL database that is based on the Apache-backed CouchDB project and the open source BigCouch project.

2] ___________________________________________________________________ Cloudant was purchased by IBM, from a company called Cloudant, in order to have an entry into document oriented NoSQL market. Cloudant's service provides integrated data management, search, and analytics engine designed for W_?_ applications.

3] Cloudant scales databases on the CouchDB framework and provides hosting, administrative tools, analytics and commercial support for CouchDB and BigCouch; it has the added advantage of data being redundantly distributed over multiple M_?_.

4] ___________________________________________________________________ _?_ is an IB_?_ software

product, which is primarily delivered as a cloud-based NoSQL service to support document management in Web applications over multiple machines.

MongoDB Document Oriented NoSQL

Look up and read about “MongoDB”. Start with Wikipedia. MongoDB is a “Documented Oriented” NoSQL

Database.

Page 17: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 17 |

1] ___________________________________________________________________ The name MongoDB was

taken “ humongous”. MongoDB is a free and open-source cross-platform whose focus is to provide a D_?_-oriented database.

2] ___________________________________________________________________ MongoDB is classified as a

NoSQL database; it avoids the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas. MongoDB calls the format BS_?_.

3] ________ {T/F} As of July 2015, MongoDB is the fourth most popular type of database management system,

and the most popular for document stores. 4] ___________________________________________________________________ _?_ is a free and open-

source cross-platform whose focus is to provide a document-oriented database; it is based on the BSON format.

Presentation #2

Return To The Presentation! 1] According to the presentation, Relational Database has three major features that are missing from NoSQL

databases. List them

___________________________________________________________________ No J_?_ Support

___________________________________________________________________ No Complex T_?_ Support

___________________________________________________________________ No C_?_ Support 2] According to the presentation, NoSQL databases offer three major features that are missing from Relational

databases. List them

___________________________________________________________________ There are Qu_?_ Language support designed for non-relational structures.

___________________________________________________________________ F_?_ Performance

___________________________________________________________________ Horizontally S_?_ to handle much more data.

3] ___________________________________________________________________ {Relational

Database/NoSQL} provides “much more functionality”. 4] ___________________________________________________________________ {Relational

Database/NoSQL} offers “much better performance" when using thousands of servers in hundreds of data centers.

5] ___________________________________________________________________ A Table in a Relational

Database will have R_?_. 6] ___________________________________________________________________ A Table in a Relational

Database would be comparable to a C_?_ in NoSQL. 7] ___________________________________________________________________ In a Relational Database

each record represents one I_?_ of entity.

Page 18: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 18 |

8] ___________________________________________________________________ In a Relational Database each record will have multiple F_?_.

9] ___________________________________________________________________ MongoDB is a D_?_

oriented database.

10] ___________________________________________________________________ The JSON like format, used

by MongoDB is called B_?_. 11] ___________________________________________________________________ The BSON code, above,

might represent one document; it would be equivalent to one R_?_ in a relational database.

12] ___________________________________________________________________ In MongoDB, the BSON

code, above, might represent _?_ documents.

13] ___________________________________________________________________ In MongoDB, the BSON documents might also be called O_?_.

14] ___________________________________________________________________ In MongoDB, multiple

documents form a C_?_ 15] ___________________________________________________________________ In MongoDB, a document is

comparable to a _?_ in a relational database. 16] ___________________________________________________________________ In MongoDB, a collection is

comparable to a _?_ in a relational database.

17] ___________________________________________________________________ Each F_?_ in the BSON

document is a key-value pair.

Page 19: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 19 |

18] ___________________________________________________________________ The BSON code above has

_?_ key value pairs one of those key-value pairs is Department & 20.

19] ___________________________________________________________________ The BSON code above has

_?_ key value pairs one of those key-value pairs is First Name & Bill. 20] ___________________________________________________________________ In MongoDB, there is a

mandatory field, called _?_, that is mandatory; it is the equivalent of a primary key in relational database. 21] ________ {T/F} In a relational database, all records must have the same number of fields. 22] ________ {T/F} In a MongoDB database, all records must have the same number of fields.

23] ________ {T/F} In the MongoDB, the project field above might have multiple values. 24] ___________________________________________________________________ In the BISON code above,

Hassan is involved in _?_ projects. 25] ___________________________________________________________________ In the BISON code above,

Bill is involved in _?_ projects. 26] ________ {T/F} MongoDB supports “1-to-Many” Relationships.

27] ________ {T/F} The BSON code above, shows how two addresses might be embedded within the Address field

for Hassan.

Page 20: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 20 |

28] ________ {T/F} NoSQL means you “Can’t Query”!

29] ___________________________________________________________________ The MongoDB query above

shows how one might search the Employee collection for a record whose _id = _?_. 30] ___________________________________________________________________ Write the MongoDB query

that might be used to search the Employee collection for records in which the name = "Hicks, Tom" 31] ___________________________________________________________________ Write the MongoDB query

that might be used to search the Employee collection for records in which the age = 21 32] ___________________________________________________________________ Write the MongoDB query

that might be used to find all of the employees. 33] ___________________________________________________________________ Write the MongoDB query

that might be used to find all of the employees and sort them by name. 34] ________ {T/F} MongoDB supports Ad Hoc Queries.

35] ________ {T/F} MongoDB supports Search By Field Queries.

36] ________ {T/F} MongoDB supports Search By Range Queries.

37] ________ {T/F} MongoDB supports Search By Regular Expression Queries.

38] ________ {T/F} MongoDB supports Indexing.

39] ________ {T/F} MongoDB supports Replication.

40] ________ {T/F} MongoDB supports Duplication of Data on Multiple Computers.

41] ________ {T/F} MongoDB supports Load Balancing.

42] ________ {T/F} MongoDB supports Horizontal Scalability; new machines can be added to a running system.

43] ________ {T/F} MongoDB could be used as a File Storage System using GridFS.

44] ________ {T/F} MongoDB supports Aggregation MapReduce can be used for the batch processing of Data. SQL

GROUP BY is supported.

45] ___________________________________________________________________ M _?_ is where you would

"divide the big computation into smaller pieces and send each piece to a smaller subset of data and once each small piece of computation is finished you abbreviate the results back".

46] ________ {T/F} In MongoDB, you can use JavaScript functions in the queries.

47] ___________________________________________________________________ MongoDB is developed and

supported by a company called 10gen and was production ready in the year 2_ _ _;

48] ___________________________________________________________________ The company 10gen has recently changed it’s name to _?_.

Page 21: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 21 |

Search The Web

Go to https://www.mongodb.com/download-center#community 1] ___________________________________________________________________ The current stable release

of MongoDB is _._._?

2] ___________________________________________________________________ MongoDB is available for {Mac/Windows/Linux}.

Go to https://www.mongodb.com/who-uses-mongodb 3] In your opinion, what are the six largest companies that use MongoDB? List them.

________________________________________ ________________________________________

________________________________________ ________________________________________

________________________________________ ________________________________________

4] ________ {T/F} MongoDB can be used for Big Data applications, 5] ________ {T/F} MongoDB can be used for Small Data applications, 6] ________ {T/F} MongoDB will be better than Relational Databases for Small Data Applications.

7] Check those applications that have MongoDB driver support.

______ Java ______ Javascript ______ Python ______ Ruby

[X] [X] [X] [X]

______ C# ______ PHP ______ C++ ______ .NET

[X] [X] [X] [X]

______ Node.js ______ Pearl ______Scala ______ Fortran

[X] [X] [X]

8] ___________________________________________________________________ Go to Indeed.com. Do the

search above. There are currently _?_,000+ database jobs listed (at that one site) in the United States.

9] ___________________________________________________________________ Go to Indeed.com. Do the

search above. There are currently _?_ database jobs listed (at that one site) in the United States that pay

Page 22: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 22 |

$100,000 - $300,000 a year.

10] ___________________________________________________________________ Go to Indeed.com. Do the

search above. There are currently _?_ MongoDB database jobs listed (at that one site) in the United States.

11] ___________________________________________________________________ The graphic above, shows

the downloads of several NoSQL databases. Many folks conclude from this collection of downloads, and others, that M_?_ is the most popular NoSQL database.

Differing Opinions

1] I believe that NoSQL has it's place and is here to stay, but there are a variety of opinions. Watch the video below!

MySQL vs MongoDB other side of the coin. Language is not great! https://www.youtube.com/watch?v=JWaDa8taiIQ

2] ___________________________________________________________________ {Sign/Pledge} I have

watched the Video above.

Page 23: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 23 |

For Reference – We Will Probably Not Get To Discuss

find() Match Greater Than

1] Write the line of code that you could use to display all of the faculty documents whose tuid is greater than

100004.

[db.faculty.find({tuid: {$gt : 100004}})] 2] Write the line of code that you could use to display all of the student documents whose tuid is greater than

990004 in order by name.

[db.student.find({tuid: {$gt : 990004}}).sort({name:1})]

3] Write the line of code that you could use to display all of the student documents whose name is alphabetically

greater than 'Mary' in order by name.

[db.student.find({name: {$gt : 'Mary'}}).sort({name:1})]

4] Write the line of code that you could use to display all of the administrator documents whose name is

alphabetically greater than 'Mary' in order by name.

[db.administrator.find({}).sort({name:1})]

5] Write the line of code that you could use to display all of the administrator documents whose name is

alphabetically greater than 'Grace' in order by name.

[db.administrator.find({name: {$gt : 'Grace'}}).sort({name:1})]

6] Write the line of code that you could use to display all of the administrator documents whose rating is greater

than 3.4 in order by rating.

[db.administrator.find({rating: {$gt : 3.4}}).sort({rating:1})]

find() Match Less Than

1] Write the line of code that you could use to display all of the faculty documents whose tuid is less than 100004.

[db.faculty.find({tuid: {$lt : 100004}})] 2] Write the line of code that you could use to display all of the student documents whose tuid is less than 990004

in order by name.

[db.student.find({tuid: {$lt : 990004}}).sort({name:1})]

3] Write the line of code that you could use to display all of the student documents whose name is alphabetically

less than 'Mary' in order by name.

[db.student.find({name: {$lt : 'Mary'}}).sort({name:1})]

4] Write the line of code that you could use to display all of the administrator documents whose rating is less

than 3.4 in order by rating.

[db.administrator.find({rating: {$gt : 3.4}}).sort({rating:1})]

Page 24: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 24 |

find() Match Greater Than Or Equal To

1] Write the line of code that you could use to display all of the faculty documents whose tuid is greater than or

equal to 100004.

[db.faculty.find({tuid: {$gte : 100004}})] 2] Write the line of code that you could use to display all of the student documents whose tuid is greater than or

equal to 990004 in order by name.

[db.student.find({tuid: {$gte : 990004}}).sort({name:1})]

3] Write the line of code that you could use to display all of the student documents whose name is alphabetically greater than or equal to 'Mary' in order by name.

[db.student.find({name: {$gte : 'Mary'}}).sort({name:1})]

4] Write the line of code that you could use to display all of the administrator documents whose rating is greater than or equal to 3.4 in order by rating.

[db.administrator.find({rating: {$gte : 3.4}}).sort({rating:1})]

find() Match Less Than Or Equal To

1] Write the line of code that you could use to display all of the faculty documents whose tuid is less than or equal

to 100004.

[db.faculty.find({tuid: {$lte : 100004}})] 2] Write the line of code that you could use to display all of the student documents whose tuid is less than or

equal to 990004 in order by name.

[db.student.find({tuid: {$lte : 990004}}).sort({name:1})]

3] Write the line of code that you could use to display all of the student documents whose name is alphabetically

less than or equal to 'Mary' in order by name.

[db.student.find({name: {$lte : 'Mary'}}).sort({name:1})]

4] Write the line of code that you could use to display all of the administrator documents whose rating is less

than or equal to 3.4 in order by rating.

[db.administrator.find({rating: {$lte : 3.4}}).sort({rating:1})]

find() Match Not Or Equal To

1] Write the line of code that you could use to display all of the faculty documents whose tuid is not equal to

100004.

[db.faculty.find({tuid: {$ne : 100004}})] 2] Write the line of code that you could use to display all of the student documents whose tuid is not equal to

990004 in order by name.

[db.student.find({tuid: {$ne : 990004}}).sort({name:1})]

Page 25: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 25 |

3] Write the line of code that you could use to display all of the student documents whose name is alphabetically

not equal to 'Mary' in order by name.

[db.student.find({name: {$ne : 'Mary'}}).sort({name:1})]

4] Write the line of code that you could use to display all of the administrator documents whose rating is not

equal to 3.4 in order by rating.

[db.administrator.find({rating: {$ne : 3.4}}).sort({rating:1})]

find() Multiple Conditions AND

1] Write the line of code that you could use to display all of the tenured faculty documents whose tuid is equal to

100005.

[db.faculty.find({$and: [{tuid: 100005} , {tenured: true}]}) ] 2] Write the line of code that you could use to display all of the tenured faculty documents whose tuid is greater

than or equal to 100004.

[db.faculty.find({$and: [{tuid: {$gte : 100004}} , {tenured: true}]})] 3] Write the line of code that you could use to display all of the Computer Science student documents whose tuid

is equal to 990004.

[db.student.find( {$and: [{tuid: 990004}, {major: 'Computer Science'}]} ) ]

4] Write the line of code that you could use to display all of the Computer Science student documents whose tuid is less than or equal to 990004 in order by name.

[db.student.find({$and: [{tuid: {$lte : 990004}}, {major: 'Computer Science'}]}).sort({name:1}) ]

5] Write the line of code that you could use to display all of the administrator documents whose rating is greater

than or equal to 3.4 and whose department is not Physics in order by name.

[db.administrator.find( { $and: [{rating: {$gte: 3.4}},{department: {$ne: 'Computer Science'}} ]} ).sort({name:1}) ]

db.administrator.find( {department: {$ne: 'Computer Science'}} ) db.administrator.find( {rating: {$gte: 3.4}} ) db.administrator.find( { $and: [{rating: {$gte: 3.4}},{} ]} ) db.administrator.find( { $and: [{rating: {$gte: 3.4}},{department: {$ne: 'Computer Science'}} ]} )

6] Write the line of code that you could use to display all of the administrator documents whose rating is not 1.1

and not 2.1 and not 2.1 in order by rating.

[ db.administrator.find( {$and: [{rating: {$ne: 1.1}}, {rating: {$ne: 2.1}}, {rating: {$ne: 3.1}}]} ).sort({rating:1}) ]

db.administrator.find( {rating: {$ne: 1.1}} ) db.administrator.find( {rating: {$ne: 2.1}} ) db.administrator.find( {rating: {$ne: 3.1}} ) db.administrator.find( {$and: [{rating: {$ne: 1.1}},{},{}]} ) db.administrator.find( {$and: [{rating: {$ne: 1.1}}, {rating: {$ne: 2.1}},{}]} ) db.administrator.find( {$and: [{rating: {$ne: 1.1}}, {rating: {$ne: 2.1}}, {rating: {$ne: 3.1}}]} ) db.administrator.find( {$and: [{rating: {$ne: 1.1}}, {rating: {$ne: 2.1}}, {rating: {$ne: 3.1}}]} ).sort({rating:1}) ]

Page 26: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 26 |

find() Multiple Conditions OR

1] Write the line of code that you could use to display all of the faculty documents whose tuid is either 100004 or

100005.

[db.faculty.find( {$or: [{tuid: 100005} , {tuid: 100004} ]}) ] 2] Write the line of code that you could use to display all of the student documents for students that are either

Computer Science Majors or have a tuid greater than or equal to 990003.

[db.student.find({$or: [{tuid: {$gte : 990003}} , {major: 'Computer Science'}]}) ]

3] Write the line of code that you could use to display all of the student documents whose tuid is equal to 990004.

[db.student.find( {$or: [{tuid: 990004}, {major: 'Computer Science'}]} ) ]

4] Write the line of code that you could use to display all of the Computer Science student documents whose

either female or have a tuid is less than or equal to 990003 in order by name.

[db.student.find({$or: [{tuid: {$lte : 990003}}, {gender: 'Female'}]}).sort({name:1}) ]

5] Write the line of code that you could use to display all of the administrator documents whose rating is greater

than or equal to 6.0 or whose department is Computer Science in order by name.

[db.administrator.find( { $or: [{rating: {$gte:6.0}},{department: 'Computer Science'} ]} ).sort({name:1}) ]

6] Write the line of code that you could use to display all of the administrator documents whose rating is 1.1 or

2.1 or 2.1 in order by rating.

[ db.administrator.find( {$or: [{rating: 1.1}, {rating: 2.1}, {rating: 3.1} ]} ).sort({rating:1}) ]

find() Project Only Some Of The Fields

1] Write the line of code that you could use to display all of the faculty documents.

[ db.faculty.find( {} ) or db.faculty.find() ] 2] Write the line of code that you could use to display the _id and the name for all of the faculty documents.

[ db.faculty.find( {}, {name: 1} ) ] 3] Write the line of code that you could use to display only the name for all of the faculty documents.

[ db.faculty.find( {}, {name: 1, _id: 0} ) ] 4] Write the line of code that you could use to display only the name and the major for all of the student

documents.

[ db.student.find( {}, {name: 1, major: 1, _id: 0} ) ]

Page 27: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 27 |

5] Write the line of code that you could use to display only the name and the department for all of the

administrator documents in order by name.

[ db.administrator.find( {}, {name: 1, department: 1, _id: 0} ).sort({name: 1}) ]

count()

1] Write the line of code that you could use to display the number of the faculty documents.

[ db.faculty.find().count()] 2] Write the line of code that you could use to display the number of the tenured faculty documents.

[ db.faculty.find({tenured: true}).count()] 3] Write the line of code that you could use to display the number of the Computer Science student documents.

[ db.student.find({major: 'Computer Science'}).count() ]

$regex

1] Write the line of code that you could use to all of the faculty documents that contain an 'a' in the name.

[ db.faculty.find({name : {$regex: 'a'}}) ] [ db.faculty.find({name: {$regex: /a/}}) ]

2] Write the line of code that you could use to display the number of the Administrator documents that have an 'A'

in the name.

[ db.administrator.find({name : {$regex: 'A'}}).count() ] [ db.administrator.find({name: {$regex: /A/}}).count() ]

3] Write the line of code that you could use to display all of the administrator documents that contain an 'an' in the

name.

[ db.administrator.find({name : {$regex: 'an'}}) ] [ db.administrator.find({name : {$regex: /an/}}) ] 4] Write the line of code that you could use to display all of the administrator documents that contain an 'an' in the

name. use a case insensitive search in order by name.

[ db.administrator.find({name : {$regex: 'an', $options : 'i'}}) ] [ db.administrator.find({name : {$regex: /an/i}}) ]

5] Write the line of code that you could use to display only the name and the department of all of the administrator

documents that start with an 'A' in the name use a case insensitive search.

[ db.administrator.find({name : {$regex: /A/i}}) ]

6] Write the line of code that you could use to display only the name and the department of all of the administrator documents that contain a 'A' in the name use a case insensitive search in order by name.

[ db.administrator.find({name : {$regex: /A/i}}, {name: 1, department:1, _id:0}).sort({name: 1}) ]

Page 28: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 28 |

7] Write the line of code that you could use to display all of the student documents that that begin with an 'a' in the

name. use a case insensitive search.

[ db.student.find({name : {$regex: /^A/i}}) ]

update

1] Write the line of code that you could use to change the first Administrator document, whose name is 'Francis'

change the name to 'Fran'.

[ db.administrator.update({name: 'Francis'}, {$set: {name: 'Fran'}}) ]

2] Write the line of code that you could use to change the all of the student documents, whose major is 'Computer

Science' change the major to 'Comp Sci'.

[ db.student.update({major: 'Computer Science'}, {$set: {major: 'Comp Sci'}}, {multi: true}) ]

3] Write the line of code that you could use to add a field, called deleted, to all of the Administrator documents

change the deleted to 'F'.

[ db.administrator.update({}, {$set: {deleted: 'F'}}, {multi: true}) ]

4] Write the line of code that you could use to add a field, called deleted, to all of the Student documents

change the deleted to 'F'.

[ db.student.update({}, {$set: {deleted: 'F'}}, {multi: true}) ]

5] Write the line of code that you could use to add a field, called deleted, to all of the User documents change

the deleted to 'F'.

[ db.user.update({}, {$set: {deleted: 'F'}}, {multi: true}) ]

6] Write the line of code that you could use to add a field, called deleted, to all of the Faculty documents

change the deleted to 'F'.

[ db.faculty.update({}, {$set: {deleted: 'F'}}, {multi: true}) ]

7] Write the line of code that you could use to tag the first Student document whose name is Matt change the

deleted flag to 'T'.

[ db.student.update({name: 'Matt'}, {$set: {deleted: 'T'}}) ]

What To Turn In

- - - - - - - - - - - - - No Lab Is Complete Until Both Are Complete - - - - - - - - - - - - - 1] You sign & submit the Pledge form.

a) Review the Pledge statement

b) Record the amount of time you think you spent on this lab

c) Staple all pages of this lab. Fold in half length-wise (like a hot-dog). Put your name on the outside. Place it on the professor

desk before the beginning of lecture on the day it is due. The penalty for late homework will not exceed 25% off per day.

2] Place all programming code associated with this program, if any, in the Professor’s Code Drop Box

a) I do not accept programs by mail; do not submit labs via email!

- - - - - - - - - - - - - - - - - Comments - - - - - - - - - - - - - - - - -

Page 29: MongoDB #2 - carme.cs.trinity.educarme.cs.trinity.edu/thicks/3343/Labs/MongoDB-2-HW.pdfdatabase server application. 3] _________ {T/F} Unless you install MongoDB as a service, you

MongoDB-2-HW.docx Database Systems (3343) Name _______________________ | 29 |

A] Programs that do not compile are worth little, if anything. B] If a print statement format is off, the penalties will often be less than the 25% per day late penalty; turn in the lab. You would not be

happy if you went to Best Buy and purchased a large screen TV that did everything except show the picture; you would consider it pretty worthless. Most users consider software that does not work properly pretty useless as well. If the lab is not working correctly, credit will be small (if any); you might be better to accept a 25% (1 day) late penalty and turn in the lab working correctly!

C] Start all programs early so that you can get in contact with the professor if you have problems. D] If you are turning in this lab late, you may

hand it to me if I am in the office

put it in the mail box outside my office door

slide it under the outer door to our suite {if locked}

slide it under my office door. The sooner I get late labs, the sooner the late penalty meter quits clicking.

E] Backup your programs in at least three places. Put a copy on your Y drive. Put a copy on your flash drive. Put a copy on your personal computer. Send yourself a copy in your e-mail.


Recommended