How not to insert empty object i.e { } in Mongoose schema.
Let suppose Mongoose collection is as follows
let testCollection = mongoose.Schema({
someData:{
type: []
}
Insert in Mongoose collection is as follows
let emptyObj = { }
new testCollection({
someData: emptyObj
}).save()
If this code executes, mongoose collection will be like this
db.somecollection.find().pretty()
{
"someData" : [
{ }
]
}
How to insert object in this array only if the object is not empty?