Skip to content

Commit

Permalink
chore(documentation): Add exists documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rolljee committed Aug 30, 2023
1 parent d9660d3 commit 201f36b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
42 changes: 42 additions & 0 deletions doc/7/controllers/document/exists/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
code: true
type: page
title: exists
description: Check if a document exists inside kuzzle
---

# exists

Check if a document exists.

<br/>

```js
exists (index, collection, id, [options]);
```

| Argument | Type | Description |
| ------------ | ----------------- | --------------- |
| `index` | <pre>string</pre> | Index name |
| `collection` | <pre>string</pre> | Collection name |
| `id` | <pre>string</pre> | Document ID |
| `options` | <pre>object</pre> | Query options |

### Options

Additional query options

| Options | Type<br/>(default) | Description |
| ---------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `queuable` | <pre>boolean</pre><br/>(`true`) | If true, queues the request during downtime, until connected to Kuzzle again |
| `refresh` | <pre>string</pre><br/>(`""`) | If set to `wait_for`, waits for the change to be reflected for `search` (up to 1s) |
| `silent` | <pre>boolean</pre><br/>(`false`) | If `true`, then Kuzzle will not generate notifications <SinceBadge version="7.5.3"/> |
| [`timeout`](/sdk/7/core-classes/kuzzle/query#timeout) | <pre>number</pre><br/>(`-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
9 changes: 9 additions & 0 deletions doc/7/controllers/document/exists/snippets/exists.js
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions doc/7/controllers/document/exists/snippets/exists.test.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 201f36b

Please sign in to comment.