mongoose-util
v1.1.0
Published
Small collection of opinionated helper functions for working with mongoose
Downloads
4
Readme
mongoose-util
Small collection of opinionated helper functions for working with mongoose
VersionIncrementor class
Sets up the $inc: { versionKey: 1 } in a consistant way on an update clause.
var mongoose = require( 'mongoose' ),
mongooseUtil = require( 'mongoose-util' );
var versionIncrementor = new mongooseUtil.VersionIncrementor( '_version' );
var userSchema = new Schema({
firstName: String,
lastName: String,
}, {
versionKey: versionIncrementor.versionKey
});
// setup the update clause and $inc: { _version: 1 } property
var updateClause = { firstName: 'Jimmy' };
versionIncrementor.setup( updateClause );
var userModel = mongoose.model( 'User', userSchema );
userModel.update( {}, updateClause );
rawDoc( response ) function
Returns only the raw document, instead of the rich Model object.
var mongoose = require( 'mongoose' ),
mongooseUtil = require( 'mongoose-util' );
var userSchema = new Schema({
firstName: String,
lastName: String,
}, {
versionKey: versionIncrementor.versionKey
});
var userModel = mongoose.model( 'User', userSchema );
return userModel
.findOne({})
.then( mongooseUtil.rawDoc );