node.js - mongoose嵌入子文档的问题
大家讲道理
大家讲道理 2017-04-17 14:55:25
0
1
433
const EventSchema = new Schema({
    dates: [Number],
    reason: {
        type: String,
        required: true
    },
    userId: Schema.Types.ObjectId,
    type: {
        type: String,
        required: true
    }
});
const CalendarSchema = new Schema({
    date: {
        type: Number,
        index: {
            unique: true
        }
    },
    events: [EventSchema]
});

在mongoose张这样嵌入子文档应该是没问题的吧?可我在插入子文档的时候报错了

.post(({ body }, res, next) => {
    const event = new Event(body);
    event.save()
        .then(savedEvent => {
            let promises = [];
            for (date of body.dates) {
                promises.push(Calendar.update({date}, {
                    $push: savedEvent._doc
                }));
            }
            return Promise.all(promises);
        })
        .then(() => res.end())
        .catch(next);
})

错误:
The field '_id' must be an array but is of type OID in document {_id: ObjectId('57c5a02c8890a02814771df1')}

是我哪里写错了吗?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!