我試圖執行mdg:validated-method
至insert
一個新集合,但是,我的代碼返回undefined
錯誤消息。 run
後面的console.log(profileCandidate)
返回該對象。它似乎停止在insert
工作。已驗證方法觸發並返回未定義錯誤
路徑:imports/api/profileCandidate/methods.js
import SimpleSchema from 'simpl-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import ProfileCandidate from './profileCandidate.js';
export const insertProfileCandidate = new ValidatedMethod({
name: 'profileCandidate.insert',
validate: new SimpleSchema({
'firstName': { type: String },
}).validator(),
run(profileCandidate) {
console.log("profileCandidate", profileCandidate);
ProfileCandidate.insert({
userId: Meteor.userId(),
createdAt: new Date(),
name: {
first: profileCandidate.firstName,
},
});
},
});
路徑:imports/api/profileCandidate/profileCandidate.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import SimpleSchema from 'simpl-schema';
export const ProfileCandidate = new Mongo.Collection('profileCandidate');
ProfileCandidate.schema = new SimpleSchema({
userId: {
type: String,
},
createdAt: {
type: Date,
},
name: Object,
'name.first': String,
});
ProfileCandidate.attachSchema(ProfileCandidate.schema);
爲簡單模式包SimpleSchema.debug = true啓用調試模式,有幫助嗎? –
沒有錯誤出現。就好像'ProfileCandidate.insert'不會觸發一樣。 – bp123