首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >架构不允许fileLink

架构不允许fileLink
EN

Stack Overflow用户
提问于 2016-11-10 13:13:51
回答 1查看 77关注 0票数 1

我试图在我当前的项目中使用简单模式,但由于某种原因,我无法让它工作。

这是我的模式:

代码语言:javascript
复制
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.'
  }
});

这是我的插页:

代码语言:javascript
复制
  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文件:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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:目标的结果时没有定义异常”。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-29 16:57:08

在做更多的工作时,我注意到我做错了一些事情。1.我的简单模式设置没有正确的值。2.一些问题与url中有空白有关。我能做些什么来解决这个问题呢? 3.当前我得到的错误是:“在传递调用‘注释’:ReferenceError:目标的结果时没有定义异常”。

谢谢@Khang

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40528536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档