2017-06-28 15 views
0

私は自分のフォームからSimpleSchemaにデータを挿入するのにcollection2を使用しています。 Collection2は挿入前にデータを消去するはずですが、$ pushを使用して配列を挿入すると、データは消去されません。データのないすべてのフィールドには、""が含まれます。私が知っている限り、$ setを使用してデータを消去することはできません。私は何が欠けていますか?

スニペット:Schema

const ProfileCandidateSchema = new SimpleSchema({ 
    careerHistoryPositions: { type: Array, optional: true }, 
    'careerHistoryPositions.$': { type: Object, optional: true }, 
    'careerHistoryPositions.$.uniqueId': { type: String, optional: true }, 
    'careerHistoryPositions.$.company': { 
    type: String, 
    optional: true, 
    custom: function() { 
     const shouldBeRequired = this.field('careerHistoryPositions.company').value; 

     if (!shouldBeRequired) { 
     // updates 
     if (this.isSet) { 
      if (this.operator === '$set' && this.value === null || this.value === '') return SimpleSchema.ErrorTypes.REQUIRED; 
     } 
     } 
    } 
    } 
}, { 
    clean: { 
    filter: true, 
    autoConvert: true, 
    removeEmptyStrings: true, 
    trimStrings: true, 
    getAutoValues: true, 
    removeNullsFromArrays: true 
    } 
}); 

スニペット:Update

const updatePosition = this.state.careerHistoryPositions.map((position) => { 
     ProfileCandidate.update({ 
     _id: this.state.profileCandidateCollectionId 
     }, { 
     $push: { 
      'careerHistoryPositions': { 
      uniqueId: position.uniqueId, 
      company: position.company 
      } 
     } 
     }); 
    }); 

答えて

0

あなたが挿入される物体の周りに角括弧を使用して$setとアレイを初期化することができる:

const updatePosition = this.state.careerHistoryPositions.map((position) => { 
    ProfileCandidate.update(this.state.profileCandidateCollectionId, { 
    $set: { 
     careerHistoryPositions: [{ 
     uniqueId: position.uniqueId, 
     company: position.company 
     }] 
    } 
    }); 
}); 
+0

I $ setを大括弧で囲んで 'careerHistoryPositi ons:[] '、他には何もありません。コンソールエラーやサーバーエラーはありません。何か案は? – bp123

+1

検証に失敗したようです。 –

+0

Collection2は、それがサーバー側でもクライアント側でもよいことを示しています。それは方法で実行する必要がありますか? – bp123

関連する問題