June 2015
Intermediate to advanced
192 pages
4h 8m
English
The Cradle module defines the merge method to let you update an existing document.
Here's an example where we change the call of a record from kf6gpe-7 to kf6gpe-9 by specifying its ID, and then performing a merge with the new data:
var call = "kf6gpe-7";
db.merge(id, {call: 'kf6gpe-9'}, function(error, doc) {
db.get(id, function(error, doc) {
console.log(doc);
});
});As you can see from the function, merge takes the ID of the record to merge, and a JavaScript object with the fields to replace or add to the existing object. You can also pass a callback, which is invoked by merge when the operation completes. The error value will be non-zero in the event of an error, and the document ...
Read now
Unlock full access