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')}
是我哪里写错了吗?
黄舟2017-04-17 14:57:25
書き方が間違っていませんか? 文書内ではこうなっています
var personSchema = Schema({
_id : Number,
name : String,
age : Number,
ストーリー : [{ type: Schema.Types.ObjectId, ref: 'ストーリー' }]
});
var storySchema = Schema({
_creator : { type: Number, ref: '人' } 、
タイトル : 文字列、
ファン : [{ type: Number、ref: '人' }]
});