-
-
Save robertklep/1a227242c78d7415407dfdca3617ab5b 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
const mongoose = require('mongoose'); | |
let Schema = mongoose.Schema({ name : String }); | |
let Model = mongoose.model('MyModel', Schema); | |
mongoose.Promise = Promise; | |
mongoose.connect('mongodb://localhost/foobar'); | |
Model.create({ name : 'Jack' }).then(d => { | |
console.log('Created new document, _id =', d._id); | |
// Convert to string and query. | |
return Model.find({ _id : d._id.toString() }); | |
}).then(d => { | |
if (d) { | |
console.log('Found document', d); | |
} else { | |
console.log('Unable to find document :('); | |
} | |
mongoose.disconnect(); | |
}).catch(e => console.log('Error', e)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment