我已经用猫鼬创建了这个模式
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:{}
};
元素问题存储问题对象,该对象包含提出问题的用户名,问题本身以及回答的人。
在.js文件中的某些位置,我可以获取通过简单回答的用户ID
question.buzzed.map(user=> <h1> {user._id} </h1>)
,
但是如何获得该用户名,我也为用户提供了一个架构,该架构具有名称,id,...等属性