我有一个表单,其中一个输入包含一个字段 - “companyName”:
<form method="post" id="uploadForm" enctype="multipart/form-data" enctype="multipart/form-data" action="/edit_company/<%- company.name %>" method="post">
<input class="form-control" type="text" name="companyName" value="<%- company.name %>">
<input type="submit" class="btn btn-primary" name="submit" id="submit" value="Send!">
</form>
如何使用指定的条件更新MongoDB中的公司名称?我该如何定义这个标准?
mongoose查询示例:
Company.update({"some criteria": "some criteria"}, {$set: {name: req.body.companyName} });
更新前的收集示例:
> db.companies.findOne();
{
"name" : "someName",
"salt" : "0.8330190361011773",
"_id" : ObjectId("53200580d0285e46618de6bc"),
"created" : ISODate("2014-03-12T06:58:08.166Z"),
"__v" : 0
}
答案 0 :(得分:4)
标准,即您的对象ID
=> Company.update({"_id": ObjectId("53200580d0285e46618de6bc")}, {$set: {name:req.body.companyName} });