0
votes

I am making a Todo List website with node.js and using mongoose database. In this database I have two two collecions,

  1. user colllection having schema like this : const userSchema = new mongoose.Schema({ email: String, password: String, googleId: String });
  2. list collection to store list items having schema like : const itemsSchema = { name: String } How to ensure that if a user is logged in then the item it enters in todolist belogs to him/her only ?
1

1 Answers

0
votes

In user.js add:

module.exports = mongoose.model('User', userSchema)
const mongoose = require('mongoose')

const itemsSchema = { 
  name: String,
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User'
  }
}