我试图在我当前的项目中使用简单模式,但由于某种原因,我无法让它工作。
这是我的模式:
Comments.schema = new SimpleSchema({
city: {
type: String,
label: 'The name of the city.'
},
person: {
type: String,
label: 'The name of the person.'
},
location: {
type: String,
label: 'The name of the location.'
},
title: {
type: String,
label: 'The title of the comment.'
},
content: {
type: String,
label: 'The content of the comment.'
},
fileLink: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'The url of the file.'
},
createdBy: {
type: String,
autoValue: function(){ return this.userId },
label: 'The id of the user.'
}
});
这是我的插页:
createSpark(event){
event.preventDefault();
const city = this.city.value;
const person = this.person.value;
const location = this.location.value;
const title = this.title.value;
const content = this.content.value;
const fileLink = s3Url;
insertComment.call({
city, person, location, title, content, fileLink
}, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
target.value = '';
Bert.alert('Comment added!', 'success');
}
});
}
我将从亚马逊获得的值保存在一个名为s3Url的全局变量中。我可以在没有问题的情况下console.log这个变量,但是当我想将它写入数据库时,我得到了一个“模式不允许的fileLink”错误。
有人看到我做错什么了吗?
这是我的comments.js文件:
import faker from 'faker';
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { Factory } from 'meteor/dburles:factory';
export const Comments = new Mongo.Collection('comments');
Comments.allow({
insert: () => false,
update: () => false,
remove: () => false,
});
Comments.deny({
insert: () => true,
update: () => true,
remove: () => true,
});
Comments.schema = new SimpleSchema({
city: {
type: String,
label: 'The name of the city.'
},
person: {
type: String,
label: 'The name of the person.'
},
location: {
type: String,
label: 'The name of the location.'
},
title: {
type: String,
label: 'The title of the comment.'
},
content: {
type: String,
label: 'The content of the comment.'
},
fileLink: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'The url of the file.'
},
createdBy: {
type: String,
autoValue: function(){ return this.userId },
label: 'The id of the user.'
}
});
Comments.attachSchema(Comments.schema);
我的methods.js文件:
import { Comments } from './comments';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { rateLimit } from '../../modules/rate-limit.js';
export const insertComment = new ValidatedMethod({
name: 'comments.insert',
validate: new SimpleSchema({
city: { type: String },
person: { type: String, optional: true },
location: { type: String, optional: true},
title: { type: String },
content: { type: String },
fileLink: { type: String, regEx: SimpleSchema.RegEx.Url },
createdBy: { type: String, optional: true }
}).validator(),
run(comment) {
Comments.insert(comment);
},
});
rateLimit({
methods: [
insertComment,
],
limit: 5,
timeRange: 1000,
});
在做更多的工作时,我注意到我做错了一些事情。1.我的简单模式设置没有正确的值。2.一些问题与url中有空白有关。我能做些什么来解决这个问题呢? 3.当前我得到的错误是:“在传递调用‘注释’:ReferenceError:目标的结果时没有定义异常”。
发布于 2016-11-29 16:57:08
在做更多的工作时,我注意到我做错了一些事情。1.我的简单模式设置没有正确的值。2.一些问题与url中有空白有关。我能做些什么来解决这个问题呢? 3.当前我得到的错误是:“在传递调用‘注释’:ReferenceError:目标的结果时没有定义异常”。
谢谢@Khang
https://stackoverflow.com/questions/40528536
复制相似问题