【发布时间】:2022-10-01 19:20:58
【问题描述】:
我有一个 mongodb 集合,当我从数据库返回数据时,我想填充一个嵌套字段。我只想返回特定字段,下面的代码解释更多。
this is my schema
const hallSchema = new Schema({
hallName: { type: String, required: true },
email: { type: String, required: true },
images: [{ type: String, required: true }],
});
这是我正在编写的用于获取图像数组的第一张图像的代码
chatRooms = await ChatRoom.find({ _id: convertedIds })
.populate(\"hallId\", `hallName ${images[0]}`);
上面的查询失败,因为它无效, 如何获得图像数组的第一项? 谢谢你的帮助
标签: javascript node.js mongodb find populate