Created
November 21, 2015 13:23
-
-
Save zaharidichev/ef27e521f71647c047b2 to your computer and use it in GitHub Desktop.
This file contains 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'); | |
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