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