You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ra...@apache.org on 2018/02/07 14:09:30 UTC
[incubator-openwhisk-package-cloudant] branch master updated: #112 Adding feature to insert document when overwrite and putIfAbsent… (#155)
This is an automated email from the ASF dual-hosted git repository.
rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-cloudant.git
The following commit(s) were added to refs/heads/master by this push:
new b1093a0 #112 Adding feature to insert document when overwrite and putIfAbsent… (#155)
b1093a0 is described below
commit b1093a0de181f8eec71a4c5f8c50320ea9a8a7af
Author: vipulkashyap111 <vi...@gmail.com>
AuthorDate: Wed Feb 7 09:09:28 2018 -0500
#112 Adding feature to insert document when overwrite and putIfAbsent… (#155)
If document is not present when overwrite is requested, then insert it.
---
actions/database-actions/write-document.js | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/actions/database-actions/write-document.js b/actions/database-actions/write-document.js
index b96b6af..2db401c 100755
--- a/actions/database-actions/write-document.js
+++ b/actions/database-actions/write-document.js
@@ -45,7 +45,7 @@ function main(message) {
/**
* If id defined and overwrite is true, checks if doc exists to retrieve version
- * before insert. Else inserts.
+ * before insert. Else inserts a new doc.
*/
function insertOrUpdate(cloudantDb, overwrite, doc) {
if (doc._id) {
@@ -62,8 +62,19 @@ function insertOrUpdate(cloudantDb, overwrite, doc) {
reject(err);
});
} else {
- console.error('error', error);
- reject(error);
+ if(error.statusCode === 404) {
+ // If document not found, insert it
+ insert(cloudantDb, doc)
+ .then(function (response) {
+ resolve(response);
+ })
+ .catch(function (err) {
+ reject(err);
+ });
+ } else {
+ console.error('error', error);
+ reject(error);
+ }
}
});
});
--
To stop receiving notification emails like this one, please contact
rabbah@apache.org.