I have a collection with products, and they are not all nicely formatted. Some lack data, and others are strings instead of numbers.
This behavior breaks my templating engine, I wonder if there is a fix for this.
If i just add this to the Schema:
order : { type: Number, 'default': 0 }
It does not set the value if it is not found in the collection, so I want someting like:
If order
is not set return 0
else return order
.
You can do something like this:
orders.find({}, function(err, results){
res.render('orders/index', {orders: results || 0 });
});