我正在研究 MERN 应用程序人员,我对后端有疑问!我有 2 个模型用户和管理员,我希望将用户的数据发送给管理员,并且管理员可以管理任何用户(更新、删除、添加)
问题是我正在处理两条不同的路线(用户和管理员),我无法将用户的数据发送到管理员的数据
所以这是用户的模式
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
// Create Schema
const UserSchema = new Schema({
username: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
},
birthdate:{
type: Date
},
age:{
type: Number,
pictureID: { type: mongoose.Schema.ObjectId, ref: "pictures"},
following: [{type: mongoose.Schema.ObjectId, ref: 'User'}],
followers: [{type: mongoose.Schema.ObjectId, ref: 'User'}]
});
module.exports = User = mongoose.model("users", UserSchema);
这是管理员的架构
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
// Create Schema
const AdminSchema = new Schema({
username: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
},
birthdate:{
type: Date
},
age:{
type: Number,
},
pictureID: { type: mongoose.Schema.ObjectId, ref: "pictures"},
developers: [{type: mongoose.Schema.ObjectId, ref: 'User'}],
testers: [{type: mongoose.Schema.ObjectId, ref: 'User'}]
});
module.exports = Admin = mongoose.model("admins", AdminSchema);