创建和更新记录

译者:飞龙

来源:Creating and Updating Items

创建

  1. var newRecord = {};
  2. newRecord.id = 1;
  3. newRecord.name = "John"
  4. Person.create(newRecord, function(err, results) {
  5. ...
  6. });

保存

  1. Person.find({ surname: "Doe" }, function (err, people) {
  2. // SQL: "SELECT * FROM person WHERE surname = 'Doe'"
  3. console.log("People found: %d", people.length);
  4. console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
  5. people[0].age = 16;
  6. people[0].save(function (err) {
  7. // err.msg = "under-age";
  8. });
  9. });