2017-08-23 3 views
0

スキーマを変更してupVotersを含めるまで、マイコレクション機能と挿入+更新+削除機能が正常に機能していました!追加する前に正常に動作しますが、機能するものはありません。私はaldeedシンプルなスキーマを使用しており、エラーは発生しません。問題はデフォルト値のupVotersにあります。なぜなら、私がデフォルト値をコメントするとき、すべてがスムーズに動くからです。しかし、すべてのupVoterを追跡して、一度投票できるようにする必要があります。スキーマの変更後に挿入または更新できません - Meteor JS + Mongo

アイデア?前もって感謝します!私は、[タイプ]として配列を宣言することはできません、私は訴えていたバージョンでは

upVoters: { 
    type: [String], 
    label: 'Up Voters', 
    defaultValue: [this.userId], 
    optional: true, 
    autoform: { 
     type: "hidden" 
    } 
}, 

答えて

1

Arrayあなたは型の配列を必要とする、有効なフィールドタイプではありません。 ..しかし、私はdefaultValue行を削除し、コードが働いた!!!!

0

import SimpleSchema from 'simpl-schema'; 
SimpleSchema.extendOptions(['autoform']); 

Ideas = new Mongo.Collection('ideas'); 

Ideas.allow({ 
    insert: function(userId, doc) { 
     return !!userId; 
    }, 
    update: function(userId, doc) { 
     return !!userId; 
    } 
}); 

IdeaSchema = new SimpleSchema({ 
    title: { 
     type: String, 
     label: "Title" 
    }, 
    category: { 
     type: String, 
     label: "Category" 
    }, 
    owner: { 
     type: String, 
     label: "Owner", 
     autoValue: function() { 
      return this.userId 
     }, 
     autoform: { 
      type: "hidden" 
     } 
    }, 
    createdAt: { 
     type: Date, 
     label: "Created At", 
     autoValue: function() { 
      return new Date() 
     }, 
     autoform: { 
      type: "hidden" 
     } 
    }, 
    upVoters: { 
     type: Array, 
     label: 'Up Voters', 
     defaultValue: [this.userId], 
     optional: true, 
     autoform: { 
      type: "hidden" 
     } 
    }, 
    'upVoters.$': { 
     type: String 
    }, 
}); 

Meteor.methods({ 
    deleteIdea: function(id) { 
     Ideas.remove(id); 
    } 
}); 

Ideas.attachSchema(IdeaSchema); 
関連する問題