June 2015
Intermediate to advanced
192 pages
4h 8m
English
The Cradle module provides the save method to save a new document to the database. You pass the document to save and a callback to invoke when the operation completes or fails.
Here's how to save a simple record using save:
var item = {
call: 'kf6gpe-7',
lat: 37,
lng: -122
};
db.save(item, function (error, result) {
if (error) {
console.log(error);
// Handle error
} else {
var id = result.id;
var rev = result.rev;
}
});The save method returns a JavaScript object to your callback with fields for the newly created document IDs and an internal revision number, along with a field titled ok, which should be true. As you'll see in the recipe titled Updating a Record in ...
Read now
Unlock full access