【发布时间】:2022-01-22 13:50:12
【问题描述】:
我使用 Intervention 模型上的 Mongoose 的 findById 方法查询名为 interventions 的 Mongo 集合。查询返回关联模型中定义的所有字段。
student 字段也存在于 interventions 集合中。猫鼬没有归还它。据推测,这是因为复杂的student 对象(25-30 个键/值对)未在干预模型中定义。我永远不需要将文档插入到干预模型中。
import mongoose from 'mongoose'
const { Schema } = mongoose
const interventionSchema = new Schema(
{
abs_count_excused: { type: Number },
abs_count_unexcused: { type: Number },
abs_count_total: { type: Number },
student_id: { type: Number, required: true }
}
)
const Intervention = mongoose.model(
'Intervention',
interventionSchema,
'interventions'
)
export default Intervention
是否可以在不在干预模型中定义 student 子文档的情况下检索它?
谢谢。
【问题讨论】:
-
您是否需要更新
student字段? -
不通过干预模型。