* .save(callback)

Purpose

The save() method updates your record in the database using the current attributes. It then returns the newly saved object in the callback.

Overview

Parameters

Description Accepted Data Types Required ?
1 Callback function Yes

Callback Parameters

Description Possible Data Types
1 Error Error
2 Saved Record { }

Example Usage

  1. User.find().exec(
  2. function(err,myRecords){
  3. // Grab a record off the top of the returned array and save a new attribute to it
  4. var getOneRecord = myRecords.pop();
  5. getOneRecord.name = 'Hank';
  6. getOneRecord.save(
  7. function(err,s){
  8. console.log('User with ID '+s.id+' now has name '+s.name);
  9. });
  10. });
  11. // User with ID 1 now has name Hank
  12. // Don't forget to handle your errors.
  13. // Don't forget to abide by the rules you set in your model

Notes

This is an instance method. Currently, instance methods ARE NOT TRANSACTIONAL. Because of this, it is recommended that you use the equivalent model method instead.