DEV Community

Margaret W.N
Margaret W.N

Posted on

Day 9: Set up mongoDB

Alt Text
Lets ctrl + c and ctrl + v our way out of day 9. I'll set up a database for my habit tracker by recycling and adjusting this code.

const mongoose = require ('mongoose');
const db = mongoose.connect('mongodb://localhost/habittracker');
const Habit = require('./models/habitModel');
Enter fullscreen mode Exit fullscreen mode

Created a habitModel.js file in models folder and created my model:

const mongoose = require('mongoose');

const {Schema} = mongoose;

const habitModel = new Schema(
  {
    done: { type: Boolean, default:false },
    title: { type: String},
    description: { type: String},
  }
);

module.exports = mongoose.model('Habit', habitModel );
Enter fullscreen mode Exit fullscreen mode

It's been an easy ride all through but today is one of those days where i like my PC better when it's off.

Finally, Day 9!

Top comments (0)