This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The PostsDAO must be constructed with a connected database object */ | |
function PostsDAO(db) { | |
"use strict"; | |
/* If this constructor is called without the "new" operator, "this" points | |
* to the global object. Log a warning and call it correctly. */ | |
if (false === (this instanceof PostsDAO)) { | |
console.log('Warning: PostsDAO constructor called without "new" operator'); | |
return new PostsDAO(db); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use enron | |
db.messages.update( | |
{'headers.Message-ID': '<8147308.1075851042335.JavaMail.evans@thyme>'}, | |
{$addToSet: { | |
"headers.To": "mrpotatohead@mongodb.com" | |
}}, | |
{multi: true} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use enron | |
db.messages.aggregate([ | |
{ | |
$unwind: "$headers.To" | |
}, | |
{ | |
$project: { | |
"_id": 1, | |
"headers.From": 1, | |
"headers.To": 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use enron | |
db.messages.find({$and: [{"headers.From": "andrew.fastow@enron.com"}, {"headers.To": "jeff.skilling@enron.com"}]}).count() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use photosharing | |
db.images.aggregate([ | |
{ | |
$unwind: "$tags" | |
}, | |
{ | |
$match: { tags: 'kittens'} | |
}, | |
{ | |
$group: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo bash < create_replica_set.sh | |
mongo --port 27018 < init_replica.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use hw5 | |
db.grades.aggregate([ | |
{ | |
$unwind: "$scores" | |
} | |
,{ | |
$match: { | |
"scores.type": { $ne: "quiz" } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use hw5 | |
db.zips.aggregate([ | |
/* First group via sum up of the values of the cities with the same name | |
this is because a city will have multiple zips therefore, | |
multiple entries of cities with the same name */ | |
{ | |
$group: { | |
_id: { state: "$state", city: "$city"}, | |
pop: { $sum: "$pop" } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use blog | |
db.posts.aggregate([{ | |
$unwind: "$comments" | |
}, { | |
$group: { | |
_id: "$comments.author", | |
postcount: { | |
$sum: 1 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"v" : 1, | |
"key" : { | |
"_id" : 1 | |
}, | |
"ns" : "blog.posts", | |
"name" : "_id_" | |
}, | |
{ |
NewerOlder