Skip to content

Instantly share code, notes, and snippets.

@zaharidichev
Created November 21, 2015 13:23
Show Gist options
  • Save zaharidichev/ef27e521f71647c047b2 to your computer and use it in GitHub Desktop.
Save zaharidichev/ef27e521f71647c047b2 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var schema = require('./schema');
mongoose.connect('mongodb://localhost:27017/test');
// Parameters are: model name, schema, collection name
var User = mongoose.model('User', schema, 'users');
var user = new User({
name: 'John Smith',
email: 'john@smith.io'
});
user.save(function(error) {
if (error) {
console.log(error);
process.exit(1);
}
User.find({ email: 'john@smith.io' }, function(error, docs) {
if (error) {
console.log(error);
process.exit(1);
}
console.log(require('util').inspect(docs));
process.exit(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment