I have two mongoose models: user.js
and note.js
, and two collections notes
and users
. The users will be able to save their notes. I don't know how to create relations between the collections. I want to be able to identify notes and the user that has created them, how should I do it?
const userSchema = new Schema(
{
username: {
type: String,
required: [true, "Please enter a username"],
unique: true,
},
password: {
type: String,
required: [true, "Please enter a password"],
minLength: [8, "The minimum password length is 8"],
},
},
{ timestamps: true }
);
note.js
const noteSchema = new Schema({
title: {
type: String,
},
text: {
type: String,
},
});