架构不允许使用fileLink

时间:2016-11-10 13:13:52

标签: javascript reactjs meteor simple-schema

我正在尝试在我目前的Meteor React项目中使用Simple Schema,但出于某种原因,我无法让它工作。

这是我的架构:

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这个变量但是当我想将它写入数据库时​​,我得到“架构不允许文件链接”错误。

任何人都能看到我做错了什么?

这是我的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.我的简单架构设置没有正确的价值。  有些问题与网址中有空格的事实有关。我该怎么做才能解决这个问题?  3.我得到的当前错误是:“在传递调用'comments.insert'的结果时出现异常:ReferenceError:target未定义。”

1 个答案:

答案 0 :(得分:1)

在进行更多工作的同时,我发现了一些我做错的事情。 1.我的简单架构设置没有正确的价值。有些问题与网址中有空格的事实有关。我该怎么做才能解决这个问题? 3.我得到的当前错误是:“在传递调用'comments.insert'的结果时出现异常:ReferenceError:target未定义。”

谢谢@Khang