Creating a nested schema in autoform


#1

I have a couple of subjects in mongodb and i want to have those subjects as choices when creating an examination.In the end,its desirable i have them saved in mongo like this

"examsubjects" : [
	{
		"mathematics" : "hCJes6DRwzgZzQvKK",
		"anglais": "dhdjs77d8bcidjk"
	}
],

where the subject choosen becomes the key.

This is my schema that i have in my collection

	examsubjects: {
        type: [Object]
    },
    "examsubjects.$.subject": {
        type: String,
		optional: true,
				autoform: {
					type:'select-checkbox-inline',
   options: function(){
            var cursor = Subject.find();
    return cursor.map(function(doc) {
        return {label: doc.subjectnames, value: doc._id};
    });
  }
}
    },

When i try saving a subject i have picked,my code gives me this

enter image description here

How should i correct this?.


#2

I figured out how to fix the string error like this

	examsubjects: {
            type: [Object]
        },
        "examsubjects.$.subject": {
            type: String,
			optional: true,
					autoform: {
						 noselect:true,
       options: function(){
                var cursor = Subject.find();
        return cursor.map(function(doc) {
            return {label: doc.subjectnames, value: doc._id};
        });
      }
    }
        },

but how would i make the selected subjects keys in mongo?