Deelux
Deelux

Reputation: 1195

fileLink is not allowed by schema

I'm trying to use Simple Schema in my current Meteor React project but for some reason I can't get it to work.

This is my 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.'
  }
});

And this is my insert:

  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');
          }
      });
    }

I'm saving the value I get back from amazon in a global variable called s3Url. I am able to console.log this variable without a problem but when I want to write it to the database I am getting a "fileLink is not allowed by schema" error.

Anyone see what I am doing wrong?

Here is my comments.js file:

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);

And my methods.js file:

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,
});

While working a bit more on it I noticed some things I was doing wrong. 1. I didn't have the right value for my simple schema set up. 2. Some problems have to do with the fact the url has white spaces in it. What can I do to fix this? 3. The current error I am getting is: "Exception in delivering result of invoking 'comments.insert': ReferenceError: target is not defined."

Upvotes: 1

Views: 81

Answers (1)

Deelux
Deelux

Reputation: 1195

While working a bit more on it I noticed some things I was doing wrong. 1. I didn't have the right value for my simple schema set up. 2. Some problems have to do with the fact the url has white spaces in it. What can I do to fix this? 3. The current error I am getting is: "Exception in delivering result of invoking 'comments.insert': ReferenceError: target is not defined."

Thanks @Khang

Upvotes: 1

Related Questions