Quiz: Concepts
Q.>What were the big differences in hardware over the last few
decades that MongoDB attempted to address?
1.Parallelism of cores
2.Parallelism of servers
3.Quantum computers
4.Faster clock speeds
5.More memory
1.Parallelism of cores
2.Parallelism of servers
Quiz: Scaling
Q: When scaling out horizontally (adding more servers to
contain your data), what are problems that arise as you go from, say, 1
commodity server to a few dozen?
1. The original server, if incorporated into the cluster, is
more likely to fail in a given unit of time than if it had been left as a
single server.
2. The servers must communicate with one another eating up
network bandwidth
3. The need for redundancy increases as the likelihood of some
failure in the system per unit of time increases.
4. Hardware cost per server is likely to increase.
Ans
2. The servers must communicate with one another eating up
network bandwidth
3. The need for redundancy increases as the likelihood of some
failure in the system per unit of time increases.
Quiz: SQL and Complex Transactions
Q: What causes significant problems for SQL when you attempt to
scale horizontally (to multiple servers)?
1. Joins
2. Queries
3. Transactions
4. Inserts
5. Indexes
1. Joins
3. Transactions
Quiz: Documents Overview
Q.> What are some advantages of representing our data using a
JSON-like format?
1. JSON presents a flexible and concise framework for
specifying queries as well as storing records.
2. JSON syntax is similar to that of common data structures
used in many programming languages and is, therefore, familiar to developers.
3. JSON is language independent.
4. JSON is optimized for use with JavaScript.
1. JSON presents a flexible and concise framework for
specifying queries as well as storing records.
2. JSON syntax is similar to that of common data structures
used in many programming languages and is, therefore, familiar to developers.
3. JSON is language independent.
Quiz: JSON Syntax
Quiz: JSON Types
Q.> How many data types are there in JSON?
a. 1 (just strings)
b. 2
c. 4
d. 6
d. 6
Q.> What is the corresponding JSON for the following XML
document?
<person>
<name>John</name>
<age>25</age>
<address>
<city>New
York</city>
<postalCode>10021</postalCode>
</address>
<phones>
<phone
type="home">212-555-1234</phone>
<phone
type="mobile">646-555-1234</phone>
</phones>
</person>
{
"name" : "John",
"age" : 25,
"address" : { "city" : "New
York", "postalCode" : "10021" },
"phones" : [
{"phone":"212-555-1234", "type" :
"home"}, {"phone":"646-555-1234",
"type" : "mobile"} ]
}
Quiz: JSON Syntax 2
Q.> For the following XML, Is the corresponding JSON example
legal json?
<things>
<hat>one</hat>
<coat>z</coat>
<hat>two</hat>
</things>
{
"hat" :
"one",
"coat" :
"z",
"hat" :
"two"
}
1. Yes
2. No
3. Maybe
3. Maybe
Quiz: Binary JSON
Q.> Why do we represent our data as BSON rather than JSON in the
system?
- Fast machine scanability.
- Human readability.
- Stronger typing (and more types) than JSON
1. Fast machine scanability.
3. Stronger typing (and more types) than JSON
Quiz: BSON and applications
Q.> For a typical client (a python client, for example) that is
receiving the results of a query in BSON, would we convert from BSON to JSON to
the client's native data structures (for example, nested dictionaries and lists
in Python), or would we convert from BSON straight to those native data
structures?
- BSON -> Native data structures
- BSON -> JSON -> Native data structures
- BSON -> Native data structures
Quiz: Dynamic Schema
Q.> True or False: MongoDB is schemaless because a schema isn't
very important in MongoDB
- True
- False
2. False
Quiz: What is the MongoDB shell?
Q: By default, which database does the mongo shell connect
to?
- test
- localhost
- mongo
- help
- default
- test
Quiz: Mongoimport
The mongoimport utility can import what types of data?
- JSON
- CSV
- BSON
- TSV
- XML
- JSON
- CSV
- BSON
- TSV
Quiz: Cursors Introduction
In order to query a collection in the mongo shell, we can
type which of the following?
- db.collection.find()
- db.find()
- db.collection.get()
- db.collection.select(*)
- db.collection.get(true)
5. db.collection.find()
None: Query Language: Basic Concepts
Q.> You have a collection where every document has the same
fields, and you want to look at the value of the “_id”, "name", and
“email” fields in order to see their format. Furthermore, you want to eliminate
all other fields from the query results. What query might you write?
- db.collection.find({ name : 1, email: 1 }, {} )
- db.collection.find( { } , { name: 1 , email: 1 } )
- db.collection.find( { name: 1 } , { email : 1 } )
- db.collection.find( {name: 1 , email: 1 } )
2. db.collection.find( { } , { name: 1 , email: 1 } )
Quiz: Query Language: Projection
Q.> You want to query the “people” collection, you want the
results of the query to include only documents where age is 50, and you want to
look at all fields except “email”. What query should you write?
- db.people.find( { email : 0, age : 50 } , { } )
- db.people.find( { email : 0 }, { age : 50 } )
- db.people.find( { age : 50 } , {email: 0 } )
- db.people.find( { } , { email : 0 , age : 50 } )
- db.people.find( { age : 50 }, {email : 1} )
3. db.people.find( { age : 50 } , {email: 0 } )
Quiz: Query Language: Advantages of a Dynamic Schema
Q.> If you want to add a new key: value pair to the documents in
the “shapes” collection, what methods could you use?
- db.shapes.alterCollection()
- db.shapes.update()
- db.shapes.resizeObject()
- db.shapes.find()
- db.shapes.save()
2. db.shapes.update()
4. db.shapes.save()
Quiz: Sorting
Q.> If you want to run a query on the collection, “books,” and
sort ASCIIbetically by title on the query, which of the following will work?
- db.books.find( { } , { sort : { title : 1 } } )
- db.books.find( { } , { title : "$sort" } )
- db.books.find( { } ).sort( { title : -1 } )
- db.books.sort( { title : 1 } ).find( { } )
- db.books.find().sort( { title : 1 } )
Ans.
5. db.books.find().sort( { title : 1 } )
Quiz: Query Language: Cursors
Q. > Recall the documents in the scores collection:
{
"_id"
: ObjectId("50844162cb4cf4564b4694f8"),
"student"
: 0,
"type"
: "exam",
"score"
: 75
}
Write a query that retrieves documents of type
"exam", sorted by score in descending order, skipping the first 50
and showing only the next 20.
db.scores.find( { type :
"exam" } ).sort( { score : -1 } ).skip( 50 ).limit( 20 )
Homework: Homework 1.1
Download and install MongoDB from www.mongodb.org. Then run
the database as a single server instance on your PC (that is, run the mongod
binary). Then, run the administrative shell.
From the shell prompt type
db.isMaster().maxBsonObjectSize
at the ">" prompt.
What do you get as a result?
Ans.
16777216
Homework: Homework 1.2
Download the handout. Take a look at its content.
Now, import its contents into MongoDB, into a database
called "pcat" and a collection called "products". Use the
mongoimport utility to do this.
When done, run this query in the mongo shell:
db.products.find( { type : "case" } ).count()
What's the result?
3
Homework: Homework 1.3
At this point you should have pcat.products loaded from the
previous step. You can confirm this by running in the shell:
db.products.find()
// or:
db.products.count()
// should print out "11"
Now, what query would you run to get all the products where
brand equals the string “ACME”?
db.products.find({"brand": "ACME"})
Homework: Homework 1.4
How would you print out, in the shell, just the value in the
"name" field, for all the product documents in the collection,
without extraneous characters or braces, sorted alphabetically, ascending?
(Check all that would apply.)
1. var c = db.products.find( { } ).sort( { name : -1 } );
while( c.hasNext() ) { print( c.next().name); }
2. var c = db.products.find( { }, { name : 1, _id : 0 } ).sort(
{ name : 1 } ); while( c.hasNext() ) { print( c.next().name); }
3. var c = db.products.find( { } ).sort( { name : 1 } );
c.forEach( function( doc ) { print( doc.name ) } );
4. db.products.find( { }, { name : 1, _id : 0 } ).sort( { name
: 1 } )
2. var c = db.products.find( { }, { name : 1, _id : 0 } ).sort(
{ name : 1 } ); while( c.hasNext() ) { print( c.next().name); }
3. var c = db.products.find( { } ).sort( { name : 1 } );
c.forEach( function( doc ) { print( doc.name ) } );
4. db.products.find( { }, { name : 1, _id : 0 } ).sort( { name
: 1 } )
Great blog !! thanks for sharing.
ReplyDeleteMean stack online training
Mean stack training in hyderabad
Good and thanks for sharing useful information with us.
ReplyDeleteFull Stack online Training
Full Stack Training
Full Stack Developer Online Training