Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含产品的集合,它们的格式并不完全正确。有些缺少数据,有些是字符串而不是数字。
这种行为破坏了我的模板引擎,我想知道是否有解决方法。
如果我只是将其添加到架构中:
order : { type: Number, 'default': 0 }
如果在集合中找不到它,它不会设置值,所以我想要类似的东西:
如果order没有设置return 0其他return order。
order
return 0
return order
你可以这样做:
orders.find({}, function(err, results){ res.render('orders/index', {orders: results || 0 }); });