Uncaught Error: After filtering out keys not in the schema, your modifier is now empty

In my case, I have two collections subject , student. In web application, a form will be submitted with selected studentID and subjectCode for enrollment. However, I got this error: Uncaught Error: After filtering out keys not in the schema, your modifier is now empty.

If anyone could help me out here I would really appreciate it.
Thanks a lot.

The subject schema is like this:

const subjectSchema = new SimpleSchema({
subjectCode:{
type: String,
label: “Subject Code”,
index:true,
unique:true
},
subjectName:{
type: String,
label: “Subject Name”,
index:true,
unique:true
},
enrollment:{
type: Array,
optional: true
},
‘enrollment.$’:String,
});

For action

Template.enroll.events({
‘submit form’:function(e){
e.preventDefault();
var name = (e.target).find('[name=studentID]').val(); var subjectCode = (e.target).find(’[name=subjectCode]’).val();

subject.update(
  {subjectCode:subjectCode},
  {$push:{"enrollment.$":name}});

}
});

Looks like you should ensure your variables subjectCode and name has value and is not undefined or null. You can use the browser debugger or put in console.log().

I checked them with console.log(), these two variables can return values.

Ok, I would personally use $addToSet (https://stackoverflow.com/questions/27248556/mongodb-difference-between-push-addtoset/46040428)

I think the culprit might be here: $push:{"enrollment.$":name}} and that you should push to “enrollment” directly. You need to push to an array and “enrollment.$” is not an array, it is a value in the array.

2 Likes

Now it is working! Thank you so much! :smiley:

1 Like