我做了这两个模型,我不知道如何在食物和用户之间建立联系。
模型1:
const mongoose = require('mongoose');
const passportLocalMongoose = require('passport-local-mongoose');
var UserSchema = new mongoose.Schema({
username: String,
password: String,
repassword: String,
email: String
})
UserSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("User", UserSchema);
模型2:
var mongoose = require('mongoose');
var foodSchema = new mongoose.Schema({
name: String,
image: String,
notify: String,
createdAt: {type: Date, default: Date.now},
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
});
module.exports = mongoose.model("food", foodSchema);