Created
February 18, 2017 17:12
-
-
Save pixelprodev/8255dd852eb5e73a1d455184723f8422 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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