|
| 1 | +# Migrating to the `cloudant-node-sdk` library |
| 2 | +This document is to assist in migrating from the `nodejs-cloudant` (package: `@cloudant/cloudant`) to the newly supported [`cloudant-node-sdk`](https://github.com/IBM/cloudant-node-sdk) (package: `@ibm-cloud/cloudant`) that compatible with JavaScript and TypeScript. |
| 3 | + |
| 4 | +## Initializing the client connection |
| 5 | +There are several ways to create a client connection in `cloudant-node-sdk`: |
| 6 | +1. [Environment variables](https://github.com/IBM/cloudant-node-sdk#authentication-with-environment-variables) |
| 7 | +2. [External configuration file](https://github.com/IBM/cloudant-node-sdk#authentication-with-external-configuration) |
| 8 | +3. [Programmatically](https://github.com/IBM/cloudant-node-sdk#programmatic-authentication) |
| 9 | + |
| 10 | +[See the README](https://github.com/IBM/cloudant-node-sdk#code-examples) for code examples on using environment variables. |
| 11 | + |
| 12 | +## Other differences |
| 13 | +1. Using the `dotenv` package to store credentials in a file is not recommended. See the [external file configuration section](https://github.com/IBM/cloudant-node-sdk#authentication-with-external-configuration) in our API docs for handling this feature in our new library. |
| 14 | +1. Fetching the database object first before performing additional operations is not required. For example, in the case of updating a document you would first call `getDocument` to fetch and then `putDocument` to update. |
| 15 | +1. Plugins are not supported, but several of the plugin features exist in the new library e.g. IAM. |
| 16 | +1. The plugin for retrying failed requests is not supported. |
| 17 | + |
| 18 | +## Request mapping |
| 19 | +Here's a list of the top 5 most frequently used `nodejs-cloudant` operations and the `cloudant-node-sdk` equivalent API operation documentation link: |
| 20 | + |
| 21 | +| `nodejs-cloudant` operation | `cloudant-node-sdk` API operation documentation link | |
| 22 | +|-----------------------------|---------------------------------| |
| 23 | +|`db.get()` |[`getDocument`](https://cloud.ibm.com/apidocs/cloudant?code=node#getdocument)| |
| 24 | +|`db.view()` |[`postView`](https://cloud.ibm.com/apidocs/cloudant?code=node#postview)| |
| 25 | +|`db.find()` |[`postFind`](https://cloud.ibm.com/apidocs/cloudant?code=node#postfind)| |
| 26 | +|`db.head()` |[`headDocument`](https://cloud.ibm.com/apidocs/cloudant?code=node#headdocument)| |
| 27 | +|`db.insert()` |[`putDocument`](https://cloud.ibm.com/apidocs/cloudant?code=node#putdocument)| |
| 28 | + |
| 29 | +[A table](#reference-table) with the whole list of operations is provided at the end of this guide. |
| 30 | + |
| 31 | +The `cloudant-node-sdk` library is generated from a more complete API spec and provides a significant number of operations that do not exist in `nodejs-cloudant`. See [the IBM Cloud API Documentation](https://cloud.ibm.com/apidocs/cloudant) to review request parameter and body options, code examples, and additional details for every endpoint. |
| 32 | + |
| 33 | +## Known Issues |
| 34 | +There's an [outline of known issues](https://github.com/IBM/cloudant-node-sdk/blob/master/KNOWN_ISSUES.md) in the `cloudant-node-sdk` repository. |
| 35 | + |
| 36 | +## Reference table |
| 37 | +The table below contains a list of `nodejs-cloudant` functions and the `cloudant-node-sdk` equivalent API operation documentation link. The `cloudant-node-sdk` operation documentation link will contain the new function in a code sample e.g. `getServerInformation` link will contain a code example with `getServerInformation()`. |
| 38 | + |
| 39 | +**Note:** There are many API operations included in the new `cloudant-node-sdk` that are not available in the `nodejs-cloudant` library. The [API documentation](https://cloud.ibm.com/apidocs/cloudant?code=node) contains the full list of operations. |
| 40 | + |
| 41 | +|nodejs-cloudant function | cloudant-node-sdk function reference | |
| 42 | +|-------------------------|--------------------------------------| |
| 43 | +|`ping()`|[getServerInformation ](https://cloud.ibm.com/apidocs/cloudant?code=node#getserverinformation)| |
| 44 | +|`listDbs()/listDbsAsStream()`|[getAllDbs](https://cloud.ibm.com/apidocs/cloudant?code=node#getalldbs)| |
| 45 | +|`updates()/followUpdates()`|[getDbUpdates](https://cloud.ibm.com/apidocs/cloudant?code=node#getdbupdates)| |
| 46 | +|`replicate()/replicateDb()/enableReplication()`|[postReplicate](https://cloud.ibm.com/apidocs/cloudant?code=node#postreplicate)| |
| 47 | +|`disableReplication()`|[deleteReplicationDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#deletereplicationdocument)| |
| 48 | +|`session()`|[getSessionInformation](https://cloud.ibm.com/apidocs/cloudant?code=node#getsessioninformation)| |
| 49 | +|`uuids()`|[getUuids](https://cloud.ibm.com/apidocs/cloudant?code=node#getuuids)| |
| 50 | +|`db.destroy()`|[deleteDatabase](https://cloud.ibm.com/apidocs/cloudant?code=node#deletedatabase)| |
| 51 | +|`db.info()`|[getDatabaseInformation](https://cloud.ibm.com/apidocs/cloudant?code=node#getdatabaseinformation)| |
| 52 | +|`db.insert()`|[postDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#postdocument)| |
| 53 | +|`db.create(db_name)`|[putDatabase](https://cloud.ibm.com/apidocs/cloudant?code=node#putdatabase)| |
| 54 | +|`db.fetch()/db.list()/db.listAsStream()`|[postAllDocs](https://cloud.ibm.com/apidocs/cloudant?code=node#postalldocs)| |
| 55 | +|`db.bulk()`|[postBulkDocs](https://cloud.ibm.com/apidocs/cloudant?code=node#postbulkdocs)| |
| 56 | +|`db.bulk_get()`|[postBulkGet](https://cloud.ibm.com/apidocs/cloudant?code=node#postbulkget)| |
| 57 | +|`db.changes()`|[postChanges](https://cloud.ibm.com/apidocs/cloudant?code=node#postchanges)| |
| 58 | +|`db.destroy() with _design path`|[deleteDesignDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#deletedesigndocument)| |
| 59 | +|`db.get() with _design path`|[getDesignDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#getdesigndocument)| |
| 60 | +|`db.insert() with _design path`|[putDesignDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#putdesigndocument)| |
| 61 | +|`db.search()/db.searchAsStream()`|[postSearch](https://cloud.ibm.com/apidocs/cloudant?code=node#postsearch)| |
| 62 | +|`db.view()`|[postView](https://cloud.ibm.com/apidocs/cloudant?code=node#postview)| |
| 63 | +|`db.list() (with a filter)`|[postDesignDocs](https://cloud.ibm.com/apidocs/cloudant?code=node#postdesigndocs)| |
| 64 | +|`db.find()`|[postFind](https://cloud.ibm.com/apidocs/cloudant?code=node#postfind)| |
| 65 | +|`db.createIndex()`|[postIndex](https://cloud.ibm.com/apidocs/cloudant?code=node#postindex)| |
| 66 | +|`db.index.del()`|[deleteIndex](https://cloud.ibm.com/apidocs/cloudant?code=node#deleteindex)| |
| 67 | +|`db.destroy() with _local path`|[deleteLocalDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#deletelocaldocument)| |
| 68 | +|`db.get() with _local path`|[getLocalDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#getlocaldocument)| |
| 69 | +|`db.insert() with _local path`|[putLocalDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#putlocaldocument)| |
| 70 | +|`db.partitionInfo()`|[getPartitionInformation](https://cloud.ibm.com/apidocs/cloudant?code=node#getpartitioninformation)| |
| 71 | +|`db.partitionedList()/partitionedListAsStream()`|[postPartitionAllDocs](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionalldocs)| |
| 72 | +|`db.partitionedSearch()/partitionedSearchAsStream()`|[postPartitionSearch](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionsearch)| |
| 73 | +|`db.partitionedView()/partitionedViewAsStream()`|[postPartitionView](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionview)| |
| 74 | +|`db.partitionedFind()/partitionedFindAsStream()`|[postPartitionFind](https://cloud.ibm.com/apidocs/cloudant?code=node#postpartitionfind)| |
| 75 | +|`db.get_security()`|[getSecurity](https://cloud.ibm.com/apidocs/cloudant?code=node#getsecurity)| |
| 76 | +|`db.set_security()`|[putSecurity](https://cloud.ibm.com/apidocs/cloudant?code=node#putsecurity)| |
| 77 | +|`db.destroy()`|[deleteDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#deletedocument)| |
| 78 | +|`db.get()`|[getDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#getdocument)| |
| 79 | +|`db.head()`|[headDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#headdocument)| |
| 80 | +|`db.insert()`|[putDocument](https://cloud.ibm.com/apidocs/cloudant?code=node#putdocument)| |
| 81 | +|`db.attachment.destroy()`|[deleteAttachment](https://cloud.ibm.com/apidocs/cloudant?code=node#deleteattachment)| |
| 82 | +|`db.attachment.get/getAsStream`|[getAttachment](https://cloud.ibm.com/apidocs/cloudant?code=node#getattachment)| |
| 83 | +|`db.attachment.insert/insertAsStream`|[putAttachment](https://cloud.ibm.com/apidocs/cloudant?code=node#putattachment)| |
| 84 | +|`generate_api_key()`|[postApiKeys](https://cloud.ibm.com/apidocs/cloudant?code=node#postapikeys)| |
| 85 | +|`db.set_security()`|[putCloudantSecurityConfiguration](https://cloud.ibm.com/apidocs/cloudant?code=node#putcloudantsecurity)| |
| 86 | +|`get_cors()`|[getCorsInformation](https://cloud.ibm.com/apidocs/cloudant?code=node#getcorsinformation)| |
| 87 | +|`set_cors()`|[putCorsConfiguration](https://cloud.ibm.com/apidocs/cloudant?code=node#putcorsconfiguration)| |
| 88 | +|`db.geo()`|[getGeo](https://cloud.ibm.com/apidocs/cloudant?code=node#getgeo)| |
0 commit comments