You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by ro...@apache.org on 2015/07/12 13:56:06 UTC

[46/50] couchdb-nano git commit: Add further documentation for the db.insert function

Add further documentation for the db.insert function

The db.insert function can be used to both create and update documents. This wasn't clear from the the README and we had more than one issue raise about it on our Cloudant fork of the project. This commit shows using the function with one parameter and a callaback, and its use to update existing documents.

Project: http://git-wip-us.apache.org/repos/asf/couchdb-nano/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nano/commit/a2a32c3c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nano/tree/a2a32c3c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nano/diff/a2a32c3c

Branch: refs/heads/master
Commit: a2a32c3c3e879010b5743dde37fd3826056a766f
Parents: b2b70f7
Author: Glynn Bird <gl...@gmail.com>
Authored: Tue Jun 16 10:57:20 2015 +0100
Committer: Glynn Bird <gl...@gmail.com>
Committed: Tue Jun 16 10:57:20 2015 +0100

----------------------------------------------------------------------
 README.md | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-nano/blob/a2a32c3c/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index d73ce26..0986002 100644
--- a/README.md
+++ b/README.md
@@ -408,6 +408,26 @@ alice.insert({ crazy: true }, 'rabbit', function(err, body) {
 });
 ```
 
+The `insert` function can also be used with the method signature `db.insert(doc,[callback])`, where the `doc` contains the `_id` field e.g.
+
+~~~ js
+var alice = cloudant.use('alice')
+alice.insert({ _id: 'myid', crazy: true }, function(err, body) {
+  if (!err)
+    console.log(body)
+})
+~~~
+
+and also used to update an existing document, by including the `_rev` token in the document being saved:
+
+~~~ js
+var alice = cloudant.use('alice')
+alice.insert({ _id: 'myid', _rev: '1-23202479633c2b380f79507a776743d5', crazy: false }, function(err, body) {
+  if (!err)
+    console.log(body)
+})
+~~~
+
 ### db.destroy(docname, rev, [callback])
 
 removes revision `rev` of `docname` from couchdb.