meteor-simple-schema: Storing objects that cannot be defined

Hi, we are creating an application that needs to save user generated data. The user uploads a csv file and we create a document for each of the rows of the csv file. We later use the data in the csv in lists, edit screens and to pass to other parts of the application.

The problem we are having is that every csv file can have a different column definition. This makes it almost impossible to validate the rest of the docment we are inserting, as simple-schema does not allow black box objects (the csv data needs to be a key-value object).

Example pseudocode:

CSV = new Meteor.Collection2('csv', {
    schema: {
        uploadId: {
            type: String,
            label: "data is part of this upload"
        },
        data: {
            type: Object,
            label: "Answers in csv"
        }
    }
});

csv_data = {
    uploadId: "1234567890",
    data: {
                COL1: 1,
                COL2: "some string",
                COL3: 3.324,
                COL4: 4
    }
};

Would there be no way of telling simple-schema to just accept the object and ignore what else is in there? It is not an option for us to JSON.stringify the data as suggested earlier as we use this data all over our application, and very often want to access the data from a column directly (data.COL1 for instance) in Mongo queries (in C++ applications). The csv data can be a very large object.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 24

Most upvoted comments

This doesn’t seem to work yet. For example, defining

Testing = new Meteor.Collection("testing", {
  schema: new SimpleSchema({
    myval: {
      type: Object,
      blackbox: true
    }
  })
});

leads to this when inserting:

Testing.insert({myval: {adsad: 'adsad'}})
insert failed: Error: failed validation: undefined is not allowed by the schema
    at doValidate (http://localhost:3000/packages/collection2.js?76b52f96f3edde1cdb74529107f5a62b68ed65f3:459:13)