Created
August 25, 2011 19:12
-
-
Save jmar777/1171531 to your computer and use it in GitHub Desktop.
Model#update undefined
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 express = require('express'), | |
mongoose = require('mongoose'), | |
Model = require('./lib/model'), | |
Tap = Model.Tap; | |
app.post('/tap', function(req, res, next) { | |
var tap = new Tap(); | |
tap.name = req.body.name; | |
tap.beer = req.body.beer; | |
tap.update({ name: tap.name }, { upsert: true }, function(err) { | |
if (err) { next(err); return; } | |
respUtil.sendJsonSuccess(res); | |
}); | |
}); |
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, | |
ObjectId = Schema.ObjectId; | |
// export our models | |
var Model = module.exports = {}; | |
/** | |
* Tab Schema | |
*/ | |
var Tap = new Schema({ | |
name: { type: String, required: true }, | |
beer: { type: ObjectId, required: true }, | |
updated: { type: Date } | |
}); | |
Tap.pre('save', function(next) { | |
this.updated = Date.now(); | |
next(); | |
}); | |
Model.Tap = mongoose.model('Tap', Tap); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment