Skip to content

Instantly share code, notes, and snippets.

@benzenwen
benzenwen / gist:3297233
Created August 8, 2012 18:17 — forked from esedor/gist:1368293
Querying MongoDB in Node.JS
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);
}); }); }); });
@benzenwen
benzenwen / gist:3291079
Created August 8, 2012 00:58 — forked from esedor/gist:1368275
Connecting to MongoDB in Node.JS
var mongo = require('mongodb');
var mongoUri = 'mongodb://localhost:27017/mongoquest';
mongo.Db.connect(mongoUri, function (err, db) {
/* adventure! */
});
@benzenwen
benzenwen / aggregation.js
Created July 9, 2012 19:14 — forked from cwestin/aggregation.js
Mongo shell script and sample documents used for my aggregation talks 12/2011
// 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
}}