From 201f36b6c24d8e199ce8a5bc48c3b3da5d722f0b Mon Sep 17 00:00:00 2001 From: rolljee Date: Wed, 30 Aug 2023 09:04:52 +0200 Subject: [PATCH 1/2] chore(documentation): Add exists documentation --- doc/7/controllers/document/exists/index.md | 42 +++++++++++++++++++ .../document/exists/snippets/exists.js | 9 ++++ .../document/exists/snippets/exists.test.yml | 11 +++++ 3 files changed, 62 insertions(+) create mode 100644 doc/7/controllers/document/exists/index.md create mode 100644 doc/7/controllers/document/exists/snippets/exists.js create mode 100644 doc/7/controllers/document/exists/snippets/exists.test.yml diff --git a/doc/7/controllers/document/exists/index.md b/doc/7/controllers/document/exists/index.md new file mode 100644 index 000000000..a14bd21b8 --- /dev/null +++ b/doc/7/controllers/document/exists/index.md @@ -0,0 +1,42 @@ +--- +code: true +type: page +title: exists +description: Check if a document exists inside kuzzle +--- + +# exists + +Check if a document exists. + +
+ +```js +exists (index, collection, id, [options]); +``` + +| Argument | Type | Description | +| ------------ | ----------------- | --------------- | +| `index` |
string
| Index name | +| `collection` |
string
| Collection name | +| `id` |
string
| Document ID | +| `options` |
object
| Query options | + +### Options + +Additional query options + +| Options | Type
(default) | Description | +| ---------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------- | +| `queuable` |
boolean

(`true`) | If true, queues the request during downtime, until connected to Kuzzle again | +| `refresh` |
string

(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) | +| `silent` |
boolean

(`false`) | If `true`, then Kuzzle will not generate notifications | +| [`timeout`](/sdk/7/core-classes/kuzzle/query#timeout) |
number

(`-1`) | Time (in ms) during which a request will still be waited to be resolved. Set it `-1` if you want to wait indefinitely | + +## Resolves + +Resolves a boolean. + +## Usage + +<<< ./snippets/exists.js diff --git a/doc/7/controllers/document/exists/snippets/exists.js b/doc/7/controllers/document/exists/snippets/exists.js new file mode 100644 index 000000000..152e97f46 --- /dev/null +++ b/doc/7/controllers/document/exists/snippets/exists.js @@ -0,0 +1,9 @@ +try { + const { result } = await kuzzle.document.exists('nyc-open-data', 'yellow-taxi', 'some-id'); + + if (result) { + console.log('Success'); + } +} catch (error) { + console.error(error.message); +} \ No newline at end of file diff --git a/doc/7/controllers/document/exists/snippets/exists.test.yml b/doc/7/controllers/document/exists/snippets/exists.test.yml new file mode 100644 index 000000000..ba7922ec6 --- /dev/null +++ b/doc/7/controllers/document/exists/snippets/exists.test.yml @@ -0,0 +1,11 @@ +name: document#exists +description: Check if a document exists in kuzzle +hooks: + before: | + curl -XDELETE kuzzle:7512/nyc-open-data + curl -XPOST kuzzle:7512/nyc-open-data/_create + curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi + curl --fail -H "Content-type: application/json" -XPUT -d '{}' kuzzle:7512/nyc-open-data/yellow-taxi/some-id + after: +template: default +expected: Success From 66c1ae2cc6226efaab2baf07707aff8103a64b1a Mon Sep 17 00:00:00 2001 From: rolljee Date: Wed, 30 Aug 2023 09:47:32 +0200 Subject: [PATCH 2/2] Exists tests --- .../document/delete-fields/snippets/deleteFields.test.yml | 2 +- doc/7/controllers/document/exists/snippets/exists.js | 6 ++---- doc/7/controllers/document/exists/snippets/exists.test.yml | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doc/7/controllers/document/delete-fields/snippets/deleteFields.test.yml b/doc/7/controllers/document/delete-fields/snippets/deleteFields.test.yml index a148e8bad..8c1e11ae2 100644 --- a/doc/7/controllers/document/delete-fields/snippets/deleteFields.test.yml +++ b/doc/7/controllers/document/delete-fields/snippets/deleteFields.test.yml @@ -1,5 +1,5 @@ name: document#delete -description: Deletes a document from kuzzle +description: Deletes a field from a document in kuzzle hooks: before: | curl -XDELETE kuzzle:7512/nyc-open-data diff --git a/doc/7/controllers/document/exists/snippets/exists.js b/doc/7/controllers/document/exists/snippets/exists.js index 152e97f46..c7a1d141e 100644 --- a/doc/7/controllers/document/exists/snippets/exists.js +++ b/doc/7/controllers/document/exists/snippets/exists.js @@ -1,9 +1,7 @@ try { - const { result } = await kuzzle.document.exists('nyc-open-data', 'yellow-taxi', 'some-id'); + const response = await kuzzle.document.exists('nyc-open-data', 'yellow-taxi', 'some-id'); - if (result) { - console.log('Success'); - } + console.log(response); } catch (error) { console.error(error.message); } \ No newline at end of file diff --git a/doc/7/controllers/document/exists/snippets/exists.test.yml b/doc/7/controllers/document/exists/snippets/exists.test.yml index ba7922ec6..795c97131 100644 --- a/doc/7/controllers/document/exists/snippets/exists.test.yml +++ b/doc/7/controllers/document/exists/snippets/exists.test.yml @@ -8,4 +8,4 @@ hooks: curl --fail -H "Content-type: application/json" -XPUT -d '{}' kuzzle:7512/nyc-open-data/yellow-taxi/some-id after: template: default -expected: Success +expected: true