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
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"); |
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
// 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({ |
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
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') |
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
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 |
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
var mongoose = require('mongoose'); | |
mongoose.connect('localhost', 'testing_populatedGetter'); | |
var Schema = mongoose.Schema; | |
var UserSchema = new Schema({ | |
name: { | |
first: { | |
type: String | |
}, |