【发布时间】:2021-08-27 08:37:09
【问题描述】:
我有两个猫鼬模型:user.js 和 note.js,还有两个集合 notes 和 users。用户将能够保存他们的笔记。我不知道如何在集合之间建立关系。我希望能够识别笔记和创建笔记的用户,我应该怎么做?
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,
},
});
【问题讨论】:
-
您可能正在寻找
ref和人口,这有帮助吗? stackoverflow.com/questions/18001478/…
标签: javascript database mongodb mongoose mongoose-schema