Skip to content

Instantly share code, notes, and snippets.

var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_multiTenant');
/**
* User schema.
*/
var UserSchema = new mongoose.Schema({
name: String
, prefix: { type: String, required: true }
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);
var mongoose = require('./../mongoose');
mongoose.connect('localhost', 'testing_twomodelsForCollection');
var schema1 = new mongoose.Schema({
name: String
}, {collection: 'mystuff'});
var schema2 = new mongoose.Schema({
var mongoose = require('./../mongoose');
var schema = new mongoose.Schema({
name: String
});
schema.methods.toString = function () { return 'hello' }
var A = mongoose.model('A', schema);
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);
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
});
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'));
Thing.methods.getWhatever = function (fn) {
buildORConditions(blah, blah, blah, function (err, ors) {
fn(null, Thing.find(ors))
});
}
var mongoose = require('./../../mongoose');
mongoose.connect('localhost', 'testing_tojsonWithVirtuals');
var schema = new mongoose.Schema({
name: {
first: String
, last: String
}
, age: Number
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)
});