This file contains hidden or 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
db.collection('quests', function(er, cl) { | |
cl.insert({'goal': 'Explore', 'lv': 1}, {safe: true}, function(er,rs) { | |
cl.update({'goal': 'Explore'}, | |
{'$set': {'gold': 150}}, {safe: true}, function(er,rs) { | |
cl.find({'lv': {'$lte': 4}}).toArray(function (er,rs) { | |
console.log(rs); | |
}); }); }); }); |
This file contains hidden or 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
var mongo = require('mongodb'); | |
var mongoUri = 'mongodb://localhost:27017/mongoquest'; | |
mongo.Db.connect(mongoUri, function (err, db) { | |
/* adventure! */ | |
}); |
This file contains hidden or 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
// make sure we're using the right db; this is the same as "use aggdb;" in shell | |
db = db.getSiblingDB("aggdb"); | |
// simple projection | |
var p1 = db.runCommand( | |
{ aggregate : "article", pipeline : [ | |
{ $project : { | |
tags : 1, | |
pageViews : 1 | |
}} |