Skip to content

Instantly share code, notes, and snippets.

@heytulsiprasad
Last active March 6, 2020 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heytulsiprasad/6e6512ec5620ae3261280a236235af80 to your computer and use it in GitHub Desktop.
Save heytulsiprasad/6e6512ec5620ae3261280a236235af80 to your computer and use it in GitHub Desktop.
shows how a basic mongoose model should look like
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