2017-08-23 28 views
0

我的集合和插入+更新+刪除功能正常工作,直到我將模式更改爲包含upVoters!沒有任何功能似乎工作,雖然他們在添加之前工作正常。我使用aldeed簡單模式,我沒有得到任何錯誤。問題在於upVoters的默認值,因爲當我評論默認值時,所有事情都可以順利進行。不過,我需要跟蹤每個upVoter,讓他們投票一次。更改模式後無法插入或更新 - 流星JS + Mongo

任何想法?提前致謝!

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); 

回答

1

Array不是有效的字段類型,你需要一個類型的數組:

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

中的版本,我起訴,我不能聲明數組爲[類型]。 ..但是,當我刪除defaultValue行,代碼工作!!!!