Skip to content

Instantly share code, notes, and snippets.

@pixelprodev
Created February 18, 2017 17:12
Show Gist options
  • Select an option

  • Save pixelprodev/8255dd852eb5e73a1d455184723f8422 to your computer and use it in GitHub Desktop.

Select an option

Save pixelprodev/8255dd852eb5e73a1d455184723f8422 to your computer and use it in GitHub Desktop.
mongoose.connect('connection string here') // <-- this saves to the singleton. your callback to confirm is fine if you just want to know that it connected for sure. :+1:
//now that mongoose is connected, you need a model in order to save a document
//schemas use json validator syntax so type declaration is Number, String, Bolean, etc (native js types)
const userSchema = mongoose.Schema({
name: String
})
const userModel = new mongoose.model('user', userSchema)
function insertIntoDatabase(name) {
new userModel({name}).save()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment