Last active
March 6, 2020 11:12
-
-
Save heytulsiprasad/6e6512ec5620ae3261280a236235af80 to your computer and use it in GitHub Desktop.
shows how a basic mongoose model should look like
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") | |
mongoose.connect("mongodb://127.0.0.1:27017/whatever-you-call", { | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true, | |
useFindAndModify: false | |
}); | |
// connect to database | |
// create a schema | |
// then create a model | |
// then export the model | |
const userSchema = new mongoose.Schema( | |
{ | |
name: { | |
type: String, | |
required: true | |
}, | |
age: { | |
type: Number | |
} | |
}, | |
{ | |
timestamps: true | |
} | |
) | |
const User = new mongoose.model("User", userSchema) | |
module.exports = User |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment