Well, I am stuck since a long time on how to treat properly an array in Node js in order to persist it in my mongobd database. I tried a lot of stuff, i am feeling close to success, but still stuck with it with the var filmDataSchema and the var film syntax.
I really need a little help, please:
Are you using mongoose? it's an elegant mongodb object modeling for node.js and has a really nice interface to handle arrays so let's say you have a student model with grades array and you want to add a new grade, you can use the '$push' (if) or $addToSet operators like so
StudentModel.update(
{ _id: student._id },
{ $addToSet: { grades: grade } }
);
StudentModel.update(
{ _id: student._id },
{ $push: { grades: grade } }
);
use $addToSet if you want only unique items to be pushed into array. use $push if you just want to add the object to array whether or not the object is already there
more about mongoose can be found here https://mongoosejs.com/