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 Schema = mongoose.Schema; | |
var assert = require('assert') | |
console.log('\n==========='); | |
console.log(' mongoose version: %s', mongoose.version); | |
console.log('========\n\n'); | |
mongoose.set('debug', true); |
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 Schema = mongoose.Schema; | |
mongoose.connect('localhost', 'testing_testmodelfindtoObject'); | |
mongoose.connection.on('error', function () { | |
console.error(arguments); | |
}); | |
var schema = new Schema({ | |
name: String |
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 Schema = mongoose.Schema; | |
mongoose.connect('localhost', 'testing_querybydate'); | |
var schema = new Schema({ | |
created: Date | |
, data: {} | |
}); | |
var A = mongoose.model('A', schema); |
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_multiTenant'); | |
/** | |
* User schema. | |
*/ | |
var UserSchema = new mongoose.Schema({ | |
name: String | |
, prefix: { type: String, required: true } |
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
=========== | |
mongoose version: 3.6.0rc0 | |
======== | |
dbname: testing_populateAdInfinitum | |
[ { title: 'blog 1', | |
author: | |
{ _id: 511bde3e3985283f25000004, |
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_emitUpdate'); | |
var Schema = mongoose.Schema; | |
var schema = new Schema({ | |
name: String | |
}); | |
// plumbing | |
schema.pre('save', function (next) { |
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 commentSchema = new Schema({ | |
body: String | |
, user: Schema.ObjectId | |
, created: { type: Date, default: Date.now } | |
}); | |
var postSchema = new Schema({ comments: [commentSchema] }); | |
var Post = mongoose.model('Post', postSchema); |
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_585'); | |
var child = { name: String }; | |
var Child = new mongoose.Schema(child); | |
var Par = new mongoose.Schema({ child: child }); | |
var P = mongoose.model('Par', Par); |
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 assert = require('assert') | |
var mongoose = require('./../mongoose'); | |
console.error( | |
'\n===========' | |
, ' mongoose version: ' | |
, mongoose.version | |
, '========\n\n' | |
); | |
var Schema = mongoose.Schema; |