ValidatorError:无法读取未定义字段上未定义的属性“选项”

时间:2016-10-07 14:30:52

标签: mongodb express

我有ShapeShapeOrientation个型号。形状可以具有许多形状取向。所以我的模型如下:

var shapeSchema = new mongoose.Schema({
  name: { type: String },
  mfrID: { type: String },
  category: { type: mongoose.Schema.Types.ObjectId, ref: 'ShapeCategory' },
  brand: { type: mongoose.Schema.Types.ObjectId, ref: 'ShapeBrand' },
  available: { type: Boolean, default: false },
  related: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Shape' }],
  orientations: [{ type: mongoose.Schema.Types.ObjectId, ref: 'ShapeOrientation' }],
  owner: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
  open: { type: Boolean, default: true },
  thumb: { type: String },
  thumbMime: { type: String },
  thumbPath: { type: String },
  shapeid: { type: String },
  desc: { type: String },
  verified: { type: Boolean, default: true }

我的形状定位模式是:

var shapeOrientationSchema = new mongoose.Schema({
  name: { type: String },
  data: { type: String },
  shape: { type: mongoose.Schema.Types.ObjectId, ref: 'Shape' },
  shapeid: { type: String },
  length: { type: Number },
  width: { type: Number },
  depth: { type: Number },
  thumb: { type: String },
  thumbMime: { type:String }
});

当我尝试同时填充形状方向和形状以进行大量导入时。

ShapeOrientation.insertMany(orientations)
  .then(function(manyDocs){
    console.log('hooked up and saved orientations.');
    async.eachSeries(manyDocs, function(orientDoc, orientDone) {
      Shape.findOne({shapeid: orientDoc.shapeid})
      .then(function(foundShape){
        foundShape.orientations.push(orientDoc._id);
        foundShape.save(function(err) {
          if(err) {
            console.log('shape', foundShape)
            console.log('cannot save shape', err)
            orientDone();
            return;
          } else {
            orientDone();
          }
          console.log('saved shape')
        })
      })
    })

我在mongo的undefined字段中收到以下错误。

cannot save shape { [ValidationError: Shape validation failed]
  message: 'Shape validation failed',
  name: 'ValidationError',
  errors:
   { undefined:
      { [ValidatorError: Cannot read property 'options' of undefined]
        properties: [Object],
        message: 'Cannot read property \'options\' of undefined',
        name: 'ValidatorError',
        kind: 'cast',
        path: undefined,
        value: undefined } } }

我似乎没有任何必填字段,我只是在填充方向时尝试保存相关数据。

形状和方向的_.id都存在,所以我不明白它为什么不能保存。

0 个答案:

没有答案