Skip to content

Instantly share code, notes, and snippets.

@aheckmann
aheckmann / repro.js
Created October 27, 2012 17:36 — forked from kevindente/repro.js
Repro for mongoose issue 1127
var vm = require("vm");
var fs = require("fs");
var path = require("path");
var schemaDecl = fs.readFileSync("schema.js", "utf8");
var mongoose = require("mongoose");
mongoose.connect("localhost", "mongoosetest");
@aheckmann
aheckmann / aggregation.js
Created August 16, 2012 14:48 — forked from TylerBrock/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.article.aggregate({
$project: { tags: 1, pageViews: 1 }
});
// unwinding an array
var u1 = db.article.aggregate({
@aheckmann
aheckmann / query
Created July 13, 2012 18:00 — forked from iamkale/query
Populate in mongoose
var mongoose = require('mongoose');
var Event = mongoose.model('Event');
var Calendar = mongoose.model('Calendar');
function eventController(app) {
app.get('/calendar/:calendarid', function (req, res) {
Calendar
.findOne({ _id:req.params.calendarid })
.populate('events')
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = Schema.ObjectId
;
mongoose.connect('mongodb://localhost/test_update_getters_setters_defaults');
var Fooschema = new Schema ({
name : { type: String, default: 'foo', required: true }
, date : Date
@aheckmann
aheckmann / gist:2207966
Created March 26, 2012 18:02 — forked from thatmarvin/gist:2204602
Mongoose does not populate virtuals? :(
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_populatedGetter');
var Schema = mongoose.Schema;
var UserSchema = new Schema({
name: {
first: {
type: String
},