我正在学习mongodb和mongoose,但我不知道如何使用此模式:
mongoose.Schema({
laps: {
type: Map,
of: [{type: ObjectId, ref:'Lap'}]
}
}, {collection: 'xxx'});
我试图像这样推动数组:
this.laps.set(key, (this.laps.get(key)).push(mongoose.Types.ObjectId(newLap._id)));
Map { '5bd1b3bfbef1001d64de6697' => ["5c0a3c0456be700670ed093b"] }
每次我尝试保存模型时,都会出现此错误:
validation failed: laps.5bd1b3bfbef1001d64de6697: Cast to [ObjectId] failed for value "[1]" at path "laps.$*"
我被困在那里