Skip to content

Instantly share code, notes, and snippets.

View hperantunes's full-sized avatar

Hilton Perantunes hperantunes

  • Montreal, Canada
View GitHub Profile
db.profile.find({op:'query', ns:'school2.students'}).sort({ millis: -1}).limit(1)
db.products.find({'brand':"GE"}).sort({price:1})
db.products.find({$and:[{price:{$gt:30}},{price:{$lt:50}}]}).sort({brand:1})
// The query uses an index to determine the order in which to return result documents.
// The query examines 251120 documents.
db.tweets.explain("executionStats").find({"user.followers_count":{$gt:1000}}).limit(10).skip(5000).sort( { created_at : 1 } )
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "twitter.tweets",
"indexFilterSet" : false,
"parsedQuery" : {
/*
Your assignment is to make the following pages fast:
The blog home page (http://localhost:57912/)
The posts page where it displays posts by tag (http://localhost:57912/Home/Posts?tag=Van)
*/
db.posts.ensureIndex({CreatedAtUtc: -1})
db.posts.ensureIndex({Tags: 1, CreatedAtUtc: -1})
HOMEWORK: HOMEWORK 6.1
Which of the following statements are true about replication in MongoDB? Check all that apply.
(X) The minimum sensible number of voting nodes to a replica set is three.
MongoDB replication is synchronous.
By default, using the new MongoClient connection class, w=1 and j=1.
(X) The oplog utilizes a capped collection.
HOMEWORK: HOMEWORK 6.2
Let's suppose you have a five member replica set and want to assure that writes are committed to the journal and are acknowledged by at least 3 nodes before you proceed forward. What would be the appropriate settings for w and j?
w=1, j=1
(X) w="majority", j=1
w=3, j=0
w=5, j=1
w=1,j=3
HOMEWORK: HOMEWORK 6.3
Which of the following statements are true about choosing and using a shard key?
The shard key must be unique
You can change the shard key on a collection if you desire.
(X) There must be a index on the collection that starts with the shard key.
(X) MongoDB can not enforce unique indexes on a sharded collection other than the shard key itself, or indexes prefixed by the shard key.
(X) Any update that does not contain the shard key will be sent to all shards.
HOMEWORK: HOMEWORK 6.4
You have a sharded system with three shards and have sharded the collections "students" in the "school" database across those shards. The output of sh.status() when connected to mongos looks like this:
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5531512ac723271f602db407")
/*
FINAL: QUESTION 7
You have been tasked to cleanup a photo-sharing database. The database consists of two collections, albums, and images. Every image is supposed to be in an album, but there are orphan images that appear in no album. Here are some example documents (not from the collections you will be downloading).
> db.albums.findOne()
{
"_id" : 67
"images" : [
4745,
FINAL: QUESTION 10
Understanding the output of explain
We perform the following query on the enron dataset:
var exp = db.messages.explain('executionStats')
exp.find( { 'headers.Date' : { '$gt' : new Date(2001,3,1) } }, { 'headers.From' : 1, '_id' : 0 } ).sort( { 'headers.From' : 1 } )
and get the following explain output.