Skip to content

Instantly share code, notes, and snippets.

@mfrobben
Created November 7, 2012 02:55
Show Gist options
  • Save mfrobben/4029328 to your computer and use it in GitHub Desktop.
Save mfrobben/4029328 to your computer and use it in GitHub Desktop.
Mongoose stuff
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
var User = new Schema({
email : { type : String, required: true, unique: true },
firstName: { type : String}
// and so on
})
exports.User = mongoose.model('User', User)
var User = require(__dirname + '/../models/user').User
User.findOne({email : req.query.email}, function(err, user){
if (err)
return res.send(500, errors.databaseError)
//can use user here
}
// You can also do var myuser = new User()
// then set attributes and call myuser.save() to insert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment