Skip to content

Instantly share code, notes, and snippets.

@bryancodesjs
Created March 19, 2023 16:33
Show Gist options
  • Save bryancodesjs/eea7dc232dcfbfefa760ecd0ba3406ad to your computer and use it in GitHub Desktop.
Save bryancodesjs/eea7dc232dcfbfefa760ecd0ba3406ad to your computer and use it in GitHub Desktop.
const mongoose = require('mongoose');
const DB_PORT = 27017;
const DB_NAME = 'playground';
mongoose.connect(`mongodb://localhost:${DB_PORT}/${DB_NAME}`)
.then(() => console.log('Connected to Mongo...'))
.catch(err => console.error('Could not connect...', err))
const courseSchema = new mongoose.Schema({
name: String,
author: String,
tags: [String],
date: { type: Date, default: Date.now},
isPublished: Boolean
})
//mongoose.model() takes two arguments, the first is the name of the model,
//the second is the schema
const Course = mongoose.model('Course', courseSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment