Skip to content

Instantly share code, notes, and snippets.

@tapmodo
Last active December 30, 2015 08:09
Show Gist options
  • Select an option

  • Save tapmodo/7800721 to your computer and use it in GitHub Desktop.

Select an option

Save tapmodo/7800721 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var _ = require('underscore');
mongoose.connect('mongodb://localhost/mydatabase');
/**
* Define a schema and model (using schema)
*/
var userSchema = mongoose.Schema({
username: String,
firstname: String,
lastname: String,
email: String,
password: String,
perms: Array
});
var User = mongoose.model('User',userSchema);
/**
* Create a new record
*/
var u = new User;
_.extend(u,{
username: 'khallman',
firstname: 'Kelly',
lastname: 'Hallman',
email: 'khallman@gmail.com',
password: 'e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4'
});
u.save(function(err,data){
console.dir(data);
/**
* Find the record
*/
User.find({ username: 'khallman' },function(err,data){
console.log(data);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment