This is my simplified collection & its schema:
Comments = new Mongo.Collection('comments');
Comments.schema = new SimpleSchema({
attachments: {type: [Object], optional: true},
});
Comments.attachSchema(Comments.schema);
And this is my simplified method:
Meteor.methods({
postComment() {
Comments.insert({
attachments: [{type:'image', value:'a'}, {type: 'image', value:'b'}]
});
}
});
After invoking the method, this is the document I've got in MongoDB:
{
"_id" : "768SmgaKeoi5KfyPy",
"attachments" : [
{},
{}
]
}
The objects in the array don't have any properties! Now if I comment this line out:
Comments.attachSchema(Comments.schema);
and call the method again, the inserted document now seems correct:
{
"_id" : "FXHzTGtkPDYtREDG2",
"attachments" : [
{
"type" : "image",
"value" : "a"
},
{
"type" : "image",
"value" : "b"
}
]
}
I must be missing something fundamental here. Please enlighten me. I'm using the latest version of Meteor (1.2.1).