【发布时间】:2020-11-29 14:04:08
【问题描述】:
我有两个模型 Post 和 Users,我想填充帖子字段
const PostSchema = new Schema({
text: {
type: String
},
author: {
type: mongoose.Schema.Types.ObjectId,
ref: 'user'
}
})
const UserSchema = new Schema({
username: {
type: String,
}
})
router.post('/', async (req,res) => {
try {
let joe = new User({username: "joe"})
await joe.save()
let postText = {text: "my name is joe", author: joe._id}
let postByJoe = new Post(postText)
await postByJoe.save()
let users = User.find().populate('author')
res.json({users})
} catch (error) {
console.log(error.message)
res.json(error.message)
}
})
问题是我得到一个错误,我不知道该怎么做。我完全不确定问题是什么。任何帮助将不胜感激
"将循环结构转换为 JSON\n --> 从具有构造函数 'NativeTopology' 的对象开始\n | 属性 's' -> 具有构造函数 'Object' 的对象\n | 属性 'sessionPool' -> 具有构造函数的对象' ServerSessionPool'\n --- 属性 'topology' 闭环"
【问题讨论】:
标签: javascript mongodb express mongoose