【发布时间】:2020-03-01 07:13:31
【问题描述】:
我用猫鼬创建了这个架构
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const QuestionSchema = new mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'users'
},
question:{
type:String
},
name:{
type:String,
},
answerd:[
{
user:{
type:mongoose.Schema.Types.ObjectId,
ref:'users'
}
}
]
})
module.exports = Question = mongoose.model('question',QuestionSchema);
在我的全局状态 (REDUX) 我有状态
const initialState = {
questions:[],
question:null,
loading:true,
error:{}
};
元素 questions 存储问题对象,其中包含提出问题的用户的姓名、问题本身以及已回答的人。
在 .js 文件中的某些地方,我可以通过简单的方式获取已回答的用户的 ID
question.buzzed.map(user=> <h1> {user._id} </h1>),
但是如何获得这个用户名,我也有一个用户模式,它具有名称、id、...等属性
【问题讨论】:
标签: node.js reactjs mongodb mongoose redux