diff --git a/doc/7/controllers/document/update/index.md b/doc/7/controllers/document/update/index.md
index a2587af85..8cc02918b 100644
--- a/doc/7/controllers/document/update/index.md
+++ b/doc/7/controllers/document/update/index.md
@@ -35,10 +35,11 @@ Additional query options
| `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) |
| `retryOnConflict` | int
(`0`) | The number of times the database layer should retry in case of version conflict |
+| `source` | boolean
(`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
diff --git a/src/controllers/document.js b/src/controllers/document.js
index 5927c846b..ea2664098 100644
--- a/src/controllers/document.js
+++ b/src/controllers/document.js
@@ -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)
diff --git a/test/controllers/document.test.js b/test/controllers/document.test.js
index e25e619ff..2cbada2b0 100644
--- a/test/controllers/document.test.js
+++ b/test/controllers/document.test.js
@@ -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);
@@ -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);