node.js - Mongoose 无法填充 ObjectId 的数组
问题描述
const { Schema } = require('mongoose');
const ModuleSchema = new Schema({
contentType: {
type: String,
default: 'module',
required: true
},
author: {
type: String,
default: 'Admin',
required: true
},
name: {
type: String,
required: true
},
content: [
{ type: Schema.Types.ObjectId, ref: 'TextBlock' }, <---- only first is rendered
{ type: Schema.Types.ObjectId, ref: 'Question' } <----- is not rendered
]
},
{timestamps: true});
-- in router
router.get('/:id', (req, res, next) => {
const id = req.params.id
Module.findById(id)
.populate('content')
.then(m => {
res.status(200).json(m)
})})
问题是我只渲染了数组内容的第一个元素。在这种情况下是一个 TextBlock。如果我交换 2 个元素,我只会得到渲染问题。
可能我使用了错误的语法,但找不到任何示例..
请帮忙
解决方案
推荐阅读
- c# - XAML 中的“名称空间错误中不存在该名称”
- jquery - JQuery 淡入然后淡出延迟 - 不工作
- php - 使用 PHP 在 Mailchimp api 3.0 中禁用双重选择
- angular - 来自不同脚本的多个 Angular 元素
- apache - 使用 apache 将特定 HTTPS 请求重定向到特定端口
- json - 用于 json 的 t-sql 在结果中跳过列名
- python - 读取 CSV 并将数据上传到 Elasticsearch
- c# - LINQ Min() 和 Max() 优化
- swift - UIImageView 与 aspectToFi 并仅裁剪图像的顶部
- c# - 使用带有 ApiController 的 signalR 和 reactjs fetch 返回数据?