Last active
April 4, 2020 07:17
-
-
Save manojnaidu619/cbb2dc0f1e8a924c7f45a7a014808ae7 to your computer and use it in GitHub Desktop.
Mongoose boilerplate
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
const mongoose = require("mongoose") | |
mongoose.connect("mongodb://127.0.0.1:27017/task-manager-api", { // establishing DB connection | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
useCreateIndex: true | |
}) | |
const User = mongoose.model('User', { | |
name: { | |
type: String // Validation | |
}, | |
age: { | |
type: Number // Validation | |
} | |
}) | |
const record = new User({ // New model instance | |
name: "Manoj", | |
age: 20 | |
}).save().then((res) => console.log(res)).catch((err)=> console.log(err)) // save() returns a promise | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment