它可以建模
const tourSchema = new Schema({
image: { type: String, required: true, trim: true },
numberOfPersons: {
name: { type: String, required: true, trim: true },
description: { type: String, required: true, trim: true },
},
})
const tourModel = mongoose.model("Tour", tourSchema);
当我使用选择
const doc = await tourModel.find(
{},
{
image: 1,
numberOfPersons: {
description: 1,
},
}
);
我得到错误
不支持的投影选项:numberOfPersons: { description: 1 }
是什么原因 ?。
您可以使用点表示法来选择 JSON 对象中的字段
const doc = await tourModel.find(
{},
{
'image': 1,
'numberOfPersons.description': 1,
}
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句