forked from prijindal/kuzzle_dart
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
code: true | ||
type: page | ||
title: upsert | ||
description: Applies partial changes to a document. If the document doesn't already exist, a new document is created. | ||
--- | ||
|
||
# upsert | ||
|
||
<SinceBadge version="Kuzzle 2.8.0"/> | ||
<SinceBadge version="auto-version" /> | ||
|
||
Applies partial changes to a document. If the document doesn't already exist, a new document is created. | ||
|
||
|
||
```dart | ||
Future<Map<String, dynamic>> upsert( | ||
String index, | ||
String collection, | ||
String id, | ||
Map<String, dynamic> changes, { | ||
bool waitForRefresh = false, | ||
int retryOnConflict, | ||
bool source, | ||
}) | ||
``` | ||
|
||
| Argument | Type | Description | | ||
| ------------ | ----------------- | ----------------------------------------- | | ||
| `index` | <pre>String</pre> | Index name | | ||
| `collection` | <pre>String</pre> | Collection name | | ||
| `id` | <pre>String</pre> | Document ID | | ||
| `changes` | <pre>Map<String, dynamic></pre> | Partial content of the document to update | | ||
|
||
### Options | ||
|
||
Additional query options | ||
|
||
| Options | Type<br/>(default) | Description | | ||
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `defaults` | <pre>Map<String, dynamic></pre><br/>(`{}`) | (optional) fields to add to the document if it gets created | | ||
| `waitForRefresh` | <pre>bool</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) | | ||
| `retryOnConflict` | <pre>int</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict | | ||
| `source` | <pre>bool</pre><br/>(`false`)| If true, returns the updated document inside the response | ||
|
||
|
||
## Returns | ||
|
||
A `Map<String, dynamic>` with the following properties: | ||
|
||
| Property | Type | Description | | ||
|------------- |--------------------------------------------- |--------------------------------- | | ||
| `_source` | <pre>Map<String, dynamic></pre> | Updated document (if `source` option set to true) | | ||
| `_id` | <pre>String</pre> | ID of the udated document | | ||
| `_version` | <pre>int</pre> | Version of the document in the persistent data storage | | ||
| `created` | <pre>bool</pre> | If `true`, a new document was created, otherwise the document existed and was updated | | ||
|
||
## Usage | ||
|
||
<<< ./snippets/upsert.dart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
final result = await kuzzle | ||
.document | ||
.upsert('nyc-open-data', 'yellow-taxi', 'some-id', { | ||
'changes': { 'category': 'suv' }, | ||
}, | ||
); |
10 changes: 10 additions & 0 deletions
10
doc/2/controllers/document/upsert/snippets/upsert.test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: document#upsert | ||
description: Applies a partial update to an existing document. | ||
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 | ||
after: | ||
template: print-result | ||
expected: "{_id: some-id, _version: 1, created: true}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters