M102 WEEK 1 QUIZ

QUIZ QUESTIONS AND ANSWERS

QUESTION : What were the big differences in hardware over the last few decades that MongoDB attempted to address?

  1. Parallelism of Cores (Ans)
  2. Parallelism of Servers (Ans)
  3. Quantum Computers
  4. Faster clock speeds
  5. Main memory

 

QUESTION: 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 server must communicate with each other eating up network bandwidth. (Ans)
  3. The need of redundancy increseases as the likelihood of some failure in the system per unit time increases. (Ans)
  4. Hardware cost per server is likely to increase

QUESTION: What causes significant problems for SQL when you attempt to scale horizontally (to multiple servers)?

  1. Joins (Ans)
  2. Queries
  3. Transactions (Ans)
  4. Inserts
  5. Indexes

QUESTION: 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. (Ans)
  2. JSON syntax is similar to that of common data structures used in many programming languages and is, therefore, familiar to developers. (Ans)
  3. JSON is language independent. (Ans)
  4. JSON is optimized to use with JavaScript

 

QUESTION: How many data types are there in JSON?

  1. 1 (just Strings)
  2. 2
  3. 4
  4. 6 (Ans) (String, Number, Object/Document, Null, Boolean(true/false))

 

QUESTION : 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>

Answer :

{“name” : “John”,”age”:25,”address”:{“city”:”New York”,”postalCode”:”10021″},”phones”:[ {“phone”:”212-555-1234″,”type” :”home”},{“phone”:”646-555-1234″,”type” :”mobile”}]}

 

QUESTION: 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”
}

  • Yes
  • No
  • Maybe (Ans)

 

QUESTION: Why do we represent our data as BSON rather than JSON in the system?

  • Fast machine scanablility (Ans)
  • Human readibility
  • Stronger typing (and more types) than JSON (Ans)

 

QUESTION: 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 (Ans)
  • BSON->JSON->Native data structures

 

QUESTION : True or False: MongoDB is schemaless because a schema isn’t very important in MongoDB

  • True
  • False (Ans)

QUESTION: By default, which database does the mongo shell connect to?

  • test (Ans)
  • localhost
  • mongo
  • help
  • default

QUESTION: The mongoimport utility can import what types of data?

  • JSON (Ans)
  • CSV (Ans)
  • BSON
  • TSV (Ans)
  • XML

QUESTION: In order to query a collection in the mongo shell, we can type which of the following?

  • db.collection.find() (Ans)
  • db.find()
  • db.collection.get()
  • db.collection.select()
  • db.collection.get(true)

QUESTION: 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}) (Ans)
  • db.collection.find({name:1{,{email:1})
  • db.collection.find({name:1,email:1})

QUESTION: 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}) (Ans)
  • db.people.find({},{email:0,age:50})
  • db.people.find({age:50},{email:1})

QUESTION: 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.shapesupdateMany() (Ans)
  • db.shapes.resizeObejct()
  • db.shapes.find()
  • db.shapes.insertOne()

QUESTION: We have sample documents in our products collection such as:

{
name: “AC1 Case Green”,
color: “green”,
price: 12.00,
for: “ac1”,
type: [“accessory”, “case”],
available: true
}
How would we query in the shell for all products that are cases for an ac9 phone? That is, where type contains the value “case” and for equals “ac9”?

Please use field names in the order they appear in the question and use double quotes around values.

Answer :
db.products.find({“type”:”case”,”for”:”ac9″})

QUESTION: 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)

QUESTION: 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.

Answer:

db.scores.find({“type”:”exam”}).sort({“score”:-1}).skip(50).limit(20)

Leave a Reply

Your email address will not be published. Required fields are marked *