我尝试将mdg:validated-method
实现为insert
新集合,但是,我的代码返回undefined
错误消息。 console.log(profileCandidate)
后run
返回对象。它似乎停止在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);
答案 0 :(得分:0)
事实证明该方法没有错误。错误在于我如何导入架构。我需要将import ProfileCandidate from './profileCandidate.js';
更改为import { ProfileCandidate } from './profileCandidate.js';
。如果有人能说明为什么你需要花括号,在这种情况下,我会很感激。