javascript - 在猫鼬模式中使用 ref 填充集合失败
问题描述
我想将信用收集填充到用户收集中,这是我的信用模式
const CreditSchema = new Schema({
userId: Schema.Types.ObjectId,
credit: {
type: Number,
default: 0
},
log: [String]
})
我的用户模式是这样的
const UserSchema = new Schema({
fullName: {
type: String,
trim: true,
required: true
},
email: {
type: String,
unique: true,
lowercase: true,
trim: true,
required: true
},
password: {
type: String,
required: true
},
credit: {type: Schema.Types.ObjectId, ref: 'Credit' } //I suspect something is not right here
})
为什么我在下面的用户对象中看不到信用?
const user = await User.findOne({_id: req.query.id})
.populate('credit')
.exec()
console.log(user) // credit field is not present?
解决方案
推荐阅读
- html - 如何使垂直字段集滚动显示
- scheme - 如果语句如何调试方案
- arrays - 如何将字符转换为整数以便将它们存储在 C 中的数组中
- c# - 使用 C# 在 Electron 应用程序上自动执行 UI 操作?
- javascript - 6 次尝试后获取 POST 未“写入”
- oauth - OAuth 客户端 ID 和猜测
- python - csv.writer 将每一行写入单独的单元格/列
- racket - 用于查找列表中与谓词匹配的第一个元素的球拍函数
- sql-server - 当值出现多次时,通过索引另一列中的值来从列创建有效地址
- r - 如何删除 0 个或多个标记(单词),它们可能会按顺序出现或中间有数据出现?