I have a MongoCollection
with a aldeed:simple-schema
attached, where the content
property has the type Object
:
The following code writes the document to console, then inserts it, then fetches the document with the correct id and writes this to console:
console.log(doc);
const id = notes.collection.insert(doc);
let newdoc = notes.collection.findOne({_id: id});
console.log(newdoc);
During the round-robin operation the value inside the object of the content property is lost.
Before the insert:
I20160304-16:52:24.722(-5)? { doctorId: 'xD7FiSfYdqwk94gQ6',
I20160304-16:52:24.723(-5)? patientId: '4wG3nnkzrfH4W2hsG',
I20160304-16:52:24.723(-5)? created: 1457128344,
I20160304-16:52:24.723(-5)? type: 'note',
I20160304-16:52:24.727(-5)? content: { noteText: 'Test' } }
When retrieved from the database:
I20160304-16:52:24.734(-5)? { _id: 'w6rRoMqtJc5EKFKFs',
I20160304-16:52:24.735(-5)? doctorId: 'xD7FiSfYdqwk94gQ6',
I20160304-16:52:24.735(-5)? patientId: '4wG3nnkzrfH4W2hsG',
I20160304-16:52:24.735(-5)? created: 1457128344,
I20160304-16:52:24.736(-5)? type: 'note',
I20160304-16:52:24.736(-5)? content: {} }
I don't understand why this happens. This is the specification of the content attribute in the simple-schema:
Carin.subschemas.object = {
type: Object,
optional: false
};
From the SimpleSchema docs:
If you have a key with type Object, the properties of the object will be validated as well, so you must define all allowed properties in the schema. If this is not possible or you don't care to validate the object's properties, use the blackbox: true option to skip validation for everything within the object.
Based on this, you either need to add blackbox: true to your schema:
Carin.subschemas.object = {
type: Object,
blackbox: true,
optional: false
};
Or you need to add all appropriate fields.