-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add document:upsert #38
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0a3992c
Add document:upsert
Yoann-Abbes 721ad00
change signature
Yoann-Abbes 8dbf89b
fix
Yoann-Abbes 9889a91
fix
Yoann-Abbes 0126294
fix
Yoann-Abbes 4c23d98
Update doc/1/controllers/document/upsert/index.md
Yoann-Abbes 212abdb
Update doc/1/controllers/document/upsert/index.md
Yoann-Abbes 90f9369
Update doc/1/controllers/document/upsert/index.md
Yoann-Abbes aeb5885
Update doc/1/controllers/document/upsert/index.md
Yoann-Abbes 3d8c453
Update doc/1/controllers/document/upsert/index.md
Yoann-Abbes 11fd5c9
fix body
Yoann-Abbes d88c483
update doc
Yoann-Abbes 2b04dca
Merge branch '1-dev' into document-upsert
Yoann-Abbes dc7c2bc
@alexandrebouthinon requested changes
Yoann-Abbes 4891cf0
Merge branch '1-dev' into document-upsert
alexandrebouthinon 8c5f439
Merge branch '1-dev' into document-upsert
Yoann-Abbes a9dcd0e
Merge branch '1-dev' into document-upsert
Yoann-Abbes bca23bf
update doc
Yoann-Abbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
--- | ||
code: true | ||
type: page | ||
title: upsert | ||
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing description |
||
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. | ||
|
||
:::: tabs | ||
::: tab Java | ||
|
||
```java | ||
public CompletableFuture<Map<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
Map<String, Object> changes) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<Map<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
Map<String, Object> changes, | ||
Map<String, Object> defaults) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<Map<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
Map<String, Object> changes, | ||
Map<String, Object> defaults, | ||
Boolean waitForRefresh) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<Map<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
Map<String, Object> changes, | ||
Map<String, Object> defaults, | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<Map<String, Object>> upsert( | ||
String index, | ||
String collection, | ||
Map<String, Object> changes, | ||
Map<String, Object> defaults, | ||
Boolean waitForRefresh, | ||
Integer retryOnConflict, | ||
Boolean source) throws NotConnectedException, InternalException | ||
``` | ||
|
||
| 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, Object></pre> | Partial content of the document to update | | ||
|
||
### Options | ||
|
||
Additional query options | ||
|
||
| Options | Type<br/>(default) | Description | | ||
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `defaults` | <pre>Map<String, Object><br/>(`{}`) | Fields to add to the document if it gets created | | ||
| `waitForRefresh` | <pre>Boolean</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) | | ||
| `retryOnConflict` | <pre>Integer</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict | | ||
| `source` | <pre>Boolean</pre><br/>(`false`)| If true, returns the updated document inside the response | ||
|
||
|
||
## Returns | ||
|
||
A `Map<String, Object>` with the following properties: | ||
|
||
| Property | Type | Description | | ||
|------------- |--------------------------------------------- |--------------------------------- | | ||
| `_source` | <pre>Map<String, Object></pre> | Updated document (if `source` option set to true) | | ||
| `_id` | <pre>String</pre> | ID of the updated document | | ||
| `_version` | <pre>Integer</pre> | Version of the document in the persistent data storage | | ||
| `created` | <pre>Boolean</pre> | ||
|
||
## Usage | ||
|
||
<<< ./snippets/upsert-java.java | ||
|
||
::: | ||
::: tab Kotlin | ||
|
||
```kotlin | ||
fun upsert( | ||
index: String, | ||
collection: String, | ||
id: String, | ||
changes: Map<String, Any?>, | ||
defaults: Map<String, Any?>, | ||
waitForRefresh: Boolean? = null, | ||
retryOnConflict: Int? = null, | ||
source: Boolean? = null): CompletableFuture<Map<String, Any?>> | ||
``` | ||
|
||
| 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, Any?></pre> | Partial content of the document to update | | ||
|
||
### Options | ||
|
||
Additional query options | ||
|
||
| Options | Type<br/>(default) | Description | | ||
| ----------------- | ------------------------------- | ---------------------------------------------------------------------------------- | | ||
| `defaults` | <pre>Map<String, Any?><br/>(`{}`) | Fields to add to the document if it gets created | | ||
| `waitForRefresh` | <pre>Boolean</pre><br/>(`""`) | If set to `true`, waits for the change to be reflected for `search` (up to 1s) | | ||
| `retryOnConflict` | <pre>Integer</pre><br/>(`10`) | The number of times the database layer should retry in case of version conflict | | ||
| `source` | <pre>Boolean</pre><br/>(`false`)| If true, returns the updated document inside the response | ||
|
||
|
||
## Returns | ||
|
||
A `Map<String, Any?>` object, with the following properties: | ||
|
||
| Property | Type | Description | | ||
|------------- |--------------------------------------------- |--------------------------------- | | ||
| `_source` | <pre>Map<String, Any?></pre> | Updated document (if `source` option set to true) | | ||
| `_id` | <pre>String</pre> | ID of the updated document | | ||
| `_version` | <pre>Integer</pre> | Version of the document in the persistent data storage | | ||
| `created` | <pre>Boolean</pre> | ||
|
||
## Usage | ||
|
||
<<< ./snippets/upsert-kotlin.kt | ||
|
||
::: | ||
:::: |
17 changes: 17 additions & 0 deletions
17
doc/1/controllers/document/upsert/snippets/upsert-java.java
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,17 @@ | ||
Map<String, Object> category = new HashMap<>(); | ||
Map<String, Object> changes = new HashMap<>(); | ||
category.put("category", "suv"); | ||
changes.put("changes", category); | ||
|
||
Map<String, Object> result = kuzzle | ||
.getDocumentController() | ||
.upsert("nyc-open-data", "yellow-taxi", "some-id", changes) | ||
.get(); | ||
|
||
/* | ||
{ | ||
created=true | ||
_id="some_id", | ||
version=1 | ||
} | ||
*/ |
10 changes: 10 additions & 0 deletions
10
doc/1/controllers/document/upsert/snippets/upsert-java.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: java-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: "{created=true, _id=some-id, _version=1}" |
15 changes: 15 additions & 0 deletions
15
doc/1/controllers/document/upsert/snippets/upsert-kotlin.kt
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,15 @@ | ||
val category: Map<String, Any?> = | ||
HashMap<String, Any?>().apply { | ||
put("category", "suv") | ||
} | ||
|
||
val changes: Map<String, Any?> = | ||
HashMap<String, Any?>().apply { | ||
put("changes", category) | ||
} | ||
|
||
val result: Map<String, Any?> = | ||
kuzzle | ||
.documentController | ||
.upsert("nyc-open-data", "yellow-taxi", "some-id", changes) | ||
.get() |
10 changes: 10 additions & 0 deletions
10
doc/1/controllers/document/upsert/snippets/upsert-kotlin.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: kotlin-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: "{created=true, _id=some-id, _version=1}" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing description