【发布时间】:2014-03-31 01:18:41
【问题描述】:
仅当新值不为空时,我才会更新设置值的集合。 我有这样的代码:
...
var userName = req.body.nome;
var userSurname = req.body.cognome;
var userAddress = req.body.indirizzo;
collection.update(
{_id:ObjectId(req.session.userID)},
{$set: { nome: userName, cognome: userSurname, indirizzo: userAddress }}
)
有没有简单的方法可以做到这一点?
另一种方式:
如果我可以从获取数据的表单的占位符中获取值req.body.*,我可以解决问题..但这可能吗?
【问题讨论】:
-
只是运行检查
if (userName != null && ... ) //db update -
这不容易,我应该尝试所有的组合
-
变量是否超过 3 个?
-
是的,我删了一些代码的问题
标签: javascript node.js mongodb