这段代码没有错误,但更新操作不起作用。在MongoDB中,更新语法可以正常工作。我通常想要根据某些条件更新特定的字段。
User.update(
{ ULId: "IC666" },
{$set: {FHName: "Arijit Banerjee",Ward:"II"}}
).done(function(err) {
if(err)
res.end(err);
res.end('success');
});
User.update(
// Find all users with ULId = IC666
{ ULId: "IC666" },
// Update their FHName and Ward fields
{FHName: "Arijit Banerjee",Ward:"II"}
).exec(function(err, users) {
// In case of error, handle accordingly
if(err) {return res.serverError(err);}
// Otherwise send a success message and a 200 status
return res.send('success');
});
.update( search criteria , values , [callback] )
update 将尝试更新与传递的条件匹配的任何记录。可以使用查询语言构建条件。
示例:
User.update({ name: 'Walter Jr' }, { name: 'Flynn' })
.exec(function(err, users) {});
这篇文章将为您更好地介绍ORM是什么以及Sails.js模型验证方法的工作原理,可能对您有用。http://www.shanison.com/2014/07/11/sails-js-model-validation/
query-methods.md
文档现已更新:https://github.com/balderdashy/waterline-docs/blob/master/queries/query-methods.md - RaviRokkam