I am working with two mongoose models: user.js
and note.js
, which correspond to the collections notes
and users
. I want users to be able to save their notes, but I'm unsure how to create relationships between these collections. Ideally, I would like to be able to identify each note along with the user who created it. How can I achieve this?
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,
},
});