I would like to create a dynamic vector/array in MongoDB. The idea is simple: whenever someone submits something, it should update a user in my database in MongoDB. I have created a variable for that. I have already tested: the proper user is found correctly.
Please, find it a snippet of my code.
User.findOne({ name })
.then(user => {
user.something.push(something to push);
})
I have set the default value when it is created as empty:
something: {
type: [String],
default: []
}
However, it does not save, and throw no error. Anyone has a guess of what might be happening behind the scenes? I am new to MongoDB.