Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/7/controllers/document/update/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ Additional query options
| `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) |
| `retryOnConflict` | <pre>int</pre><br/>(`0`) | 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

## Resolves

Resolves to an object containing the the document update result.
Resolves to an object containing the document update result.

## Usage

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ class DocumentController extends BaseController {
_id,
body,
action: 'update',
retryOnConflict: options.retryOnConflict
retryOnConflict: options.retryOnConflict,
source: options.source
};
delete options.source;
delete options.retryOnConflict;

return this.query(request, options)
Expand Down
34 changes: 32 additions & 2 deletions test/controllers/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ describe('Document Controller', () => {
collection: 'collection',
_id: 'document-id',
body: {foo: 'bar'},
retryOnConflict: undefined
retryOnConflict: undefined,
source: undefined
}, options);

should(res).be.equal(result);
Expand All @@ -539,7 +540,36 @@ describe('Document Controller', () => {
collection: 'collection',
_id: 'document-id',
body: {foo: 'bar'},
retryOnConflict: true
retryOnConflict: true,
source: undefined
}, {});

should(res).be.equal(result);
});
});

it('should inject the "source" option into the request', () => {
const result = {
_id: 'document-id',
_version: 1,
_source: { foo: 'bar' },
created: false
};
kuzzle.query.resolves({ result });

return kuzzle.document.update('index', 'collection', 'document-id', { foo: 'bar' }, { source: true })
.then(res => {
should(kuzzle.query)
.be.calledOnce()
.be.calledWith({
controller: 'document',
action: 'update',
index: 'index',
collection: 'collection',
_id: 'document-id',
body: { foo: 'bar' },
retryOnConflict: undefined,
source: true
}, {});

should(res).be.equal(result);
Expand Down