I am using the npm version of Simple Schema. I have a schema defined like this:
const PageSchema = new SimpleSchema({
organizationId: String,
title: String,
published: Boolean,
slug: String,
content: {
type: Object,
optional: true
}
})
The 'content' value is meant to contain data exported from Draft JS using Draft's convertToRaw function. However, when I clean the data using Simple Schema, the content key/value gets completely removed from the object. No errors are thrown, it just quietly deletes that node.
I certainly did not expect a side-effect like this. Is there something I'm not understanding about Simple Schema's 'Object' type? Does it expect me to serialize an object as JSON first, or something? Or maybe there is something about the object literal exported by Draft JS that it doesn't like...?
Or is it possible Draft JS is doing something in its object export that Simple Schema finds unorthodox? Is this a Draft JS problem or a Simple Schema problem?
Here's a console.log of the data before cleaning:
{ organizationId: 'JEsvMiJeTgexkAuzH',
title: 'Test Title',
published: true,
slug: 'test-title',
content: { entityMap: {}, blocks: [ [Object] ] } }
And here's what it looks like after the cleaning:
{ organizationId: 'JEsvMiJeTgexkAuzH',
title: 'Test Title',
published: true,
slug: 'test-title' }
Any pointers/help would be greatly appreciated! I have not attempted to use object literals as values before when working with meteor data, so I'm sure there's just some fundamental thing I'm missing.
UPDATE: I tried inserting the data without calling clean() first, and this actually works just fine. However, this is, of course, a far-from-ideal workaround. But it does tell me there isn't anything about the data that Mongo or meteor collections object to.