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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var assert = require('assert') | |
console.log('\n==========='); | |
console.log(' mongoose version: %s', mongoose.version); | |
console.log('========\n\n'); | |
mongoose.connect('localhost', 'testing_allquery'); |
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
// v2 | |
var childSchema = new Schema({ name: String }) | |
var parentSchema = new Schema({ children: [childSchema] }) | |
// new in v3 - inline schema declaration | |
var parentSchema = new Schema({ children: [{ name: String }] }) |
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
// v2 | |
new Schema({ name: String, age: Number }) | |
// new in v3 | |
new Schema({ name: 'string', age: 'number' }) |
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
> node -v | |
v0.8.5 | |
// faster cloning means faster updates | |
> git checkout 2.x | |
> node benchmarks/clone.js | |
took 12.738 seconds for 100000 docs (7850.525985241012 dps) |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var assert = require('assert') | |
console.log('\n==========='); | |
console.log(' mongoose version: %s', mongoose.version); | |
console.log('========\n\n'); | |
var schema = new Schema({ | |
n1: Number |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
console.log('\n==========='); | |
console.log(' mongoose version: %s', mongoose.version); | |
console.log('========\n\n'); | |
mongoose.connect('localhost', 'testing_embeddedVirtuals'); | |
mongoose.connection.on('error', function () { |
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 mongoose = require('mongoose'); | |
var Schema = mongoose.Schema; | |
var assert = require('assert') | |
console.log('\n==========='); | |
console.log(' mongoose version: %s', mongoose.version); | |
console.log('========\n\n'); | |
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 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 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 mongoose = require('./../mongoose'); | |
console.error( | |
'\n===========' | |
, ' mongoose version: ' | |
, mongoose.version | |
, '========\n\n' | |
); |
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
Cat | |
.where('name', 'Sprinkls') | |
.findOneAndUpdate({ name: 'Sprinkles' }) | |
.setOptions({ new: false }) | |
.exec(function (err, cat) { | |
if (err) .. | |
render('cat', cat); | |
}); |