I have such a scheme (fluff cutting):
Schemas.people = new SimpleSchema({ note: { type: [Schemas.notes], optional: true, defaultValue: [] }, updates: { type: [Schemas.updates], optional:true, autoValue:function(){ if (this.isInsert) { return [{ at: new Date, user_id: this.userId }]; } return { $push:{ at: new Date, user_id: this.userId } } } } });
And the notes scheme looks like this:
Schemas.notes = new SimpleSchema({ note: { type: String, autoform: { afFieldInput:{ type:"textarea" } }, optional: true }, updates: { type: [Schemas.updates], optional:true, autoform:{ omit:true }, autoValue:function(){ if (this.isInsert) { return [{ at: new Date, user_id: this.userId }]; } return { $push:{ at: new Date, user_id: this.userId } } } } });
And the update scheme is very simple:
Schemas.updates = new SimpleSchema({ at: { type: Date }, user_id:{ type: Meteor.ObjectID } });
The "update" field in the people schema stores the date / user ID as expected when the update is made. However, it does not work in the notes schema:
SimpleSchema invalid keys for "blablabla" context: 0: Object name: "note.0.updates.0.at" type: "keyNotInSchema" value: Mon May 11 2015 11:57:58 GMT-0400 (Eastern Daylight Time) 1: Object name: "note.0.updates.0.user_id" type: "keyNotInSchema" value: "abcd1234"
I believe that the "name" should look like "people.note.0.updates.0.at", but I'm not sure that this assumption is true, and I'm completely not sure how to do it.
Update:
Code used to update people
{{#autoForm collection="people" id=formId type="update" class="update" autocomplete="off" doc=getDocument autosave=true template="quickform"}} {{> afQuickField name='note' template="quickform" }} {{/autoForm}}
formId returns a random identifier string and getDocument passes the correct collection.
Schemas.notes._schemaKeys does not list the at and user_id ... but Schemas.people._schemaKeys does.
People scheme: [..., "updates. $. At", "updates. $. User_id", ...]
Scheme of notes: ["note", "updates", "updates. $"]
How strange.