I have a mongoose schema which has a field of comments: [String].
When I try to update the schema, I am checking if the value is null or empty by adding the following code into my controller,
if (req.body.comments !== null || req.body.comments !== '') {
container.comments.push(req.body.comments)
}
container.save() ...
However when I run this code (using postman for testing) and do not provide a value for the comment field, it updates in the database as null in the array.
comments: [String] is in the main schema definition and not part of a suc-document or anything like that.
Would anybody know a way round this issue or why this happens?
undefined, notnull. You should check for that case as well.