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'); | |
mongoose.connect('localhost', 'testing_multiTenant'); | |
/** | |
* User schema. | |
*/ | |
var UserSchema = new mongoose.Schema({ | |
name: String | |
, prefix: { type: String, required: true } |
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'); | |
mongoose.connect('localhost', 'testing_disconnectBeforeIndex'); | |
var user = new mongoose.Schema({ | |
username: { type: String, index: { unique: true } }, | |
password: String | |
}); | |
var model = mongoose.model('user', user); |
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'); | |
mongoose.connect('localhost', 'testing_twomodelsForCollection'); | |
var schema1 = new mongoose.Schema({ | |
name: String | |
}, {collection: 'mystuff'}); | |
var schema2 = new mongoose.Schema({ |
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 = new mongoose.Schema({ | |
name: String | |
}); | |
schema.methods.toString = function () { return 'hello' } | |
var A = mongoose.model('A', schema); |
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
schema.virtual('magic').set(function (v) { | |
this.magic = v; | |
}); | |
schema.pre('save', function (next) { | |
if (!this.magic) return next(); | |
this.model('Other') | |
.findOne({ magic: this.magick }).select('_id').exec(function (err, other) { | |
if (err || !other) return next(err); |
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') | |
, Schema = mongoose.Schema | |
, tojson = mongoose.Document.prototype.toJSON; | |
mongoose.connect('localhost', 'testing_tojsonWithVirtuals'); | |
var PersonSchema = 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
var mongoose = require('mongoose'); | |
mongoose.connect('localhost', 'testing_invalidate'); | |
var schema = new mongoose.Schema({ | |
name: String | |
}); | |
schema.methods.do = function (v) { | |
this.invalidate('name', new Error('nope')); |
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
Thing.methods.getWhatever = function (fn) { | |
buildORConditions(blah, blah, blah, function (err, ors) { | |
fn(null, Thing.find(ors)) | |
}); | |
} |
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'); | |
mongoose.connect('localhost', 'testing_tojsonWithVirtuals'); | |
var schema = new mongoose.Schema({ | |
name: { | |
first: String | |
, last: 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
var mongoose = require('./../mongoose'); | |
mongoose.connect('localhost', 'testing_enumarray'); | |
var ok = 'car figure'.split(' '); | |
function validator (v) { | |
return v.every(function (val) { | |
return !!~ok.indexOf(val) | |
}); |