From 524e5f7e99562cd03922970403a8fd9cf76b1785 Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 27 May 2019 16:15:24 +0200 Subject: [PATCH 1/3] Fix bulk import return --- .../controller-bulk/import/index.md | 14 ++++----- src/sdk/js/6/controllers/bulk/import/index.md | 2 +- .../bulk/import/snippets/import.js | 30 ++++++++++++------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/core/1/api/api-reference/controller-bulk/import/index.md b/src/core/1/api/api-reference/controller-bulk/import/index.md index bdf9c0de1..012264c4d 100644 --- a/src/core/1/api/api-reference/controller-bulk/import/index.md +++ b/src/core/1/api/api-reference/controller-bulk/import/index.md @@ -6,8 +6,6 @@ title: import # import - - Creates, updates or deletes large amounts of documents as fast as possible. This route is faster than the `document:m*` routes family (e.g. [document:mCreate](/core/1/api/api-reference/controller-document/m-create/)), but no real-time notifications will be generated, even if some of the documents in the import match subscription filters. @@ -78,12 +76,14 @@ The body must contain a `bulkData` array, detailing the bulk operations to perfo ## Response -Returns a `items` array containing the list of executed queries result, in the same order than in the query. +Returns an object containing 2 properties: + - `items`: array containing the list of executed queries result, in the same order than in the query + - `errors`: boolean indicating if some error occured during the bulk Each query result contains the following properties: - `_id`: document unique identifier -- `status`: HTTP status code for that query +- `status`: HTTP status code for that query. `201` (created) or `206` (partial error) ```javascript { @@ -99,19 +99,19 @@ Each query result contains the following properties: { "create": { "_id": "", - "status": 200 + "status": 201 } }, { "create": { "_id": "", - "status": 200 + "status": 201 } }, { "create": { "_id": "", - "status": 200 + "status": 201 } } ] diff --git a/src/sdk/js/6/controllers/bulk/import/index.md b/src/sdk/js/6/controllers/bulk/import/index.md index 3dc55c05a..459f276a9 100644 --- a/src/sdk/js/6/controllers/bulk/import/index.md +++ b/src/sdk/js/6/controllers/bulk/import/index.md @@ -75,7 +75,7 @@ Each object has the following structure: { "": { _id: "another-id", - status: 200 + status: 201 } } ``` diff --git a/src/sdk/js/6/controllers/bulk/import/snippets/import.js b/src/sdk/js/6/controllers/bulk/import/snippets/import.js index 91c0ebe3d..fa5aa1cfe 100644 --- a/src/sdk/js/6/controllers/bulk/import/snippets/import.js +++ b/src/sdk/js/6/controllers/bulk/import/snippets/import.js @@ -13,18 +13,28 @@ try { /* { errors: false, items: - [ { create: create: { - _id: "1", - status: 200 } }, - { create: create: { - _id: "2", - status: 200 } }, - { create: create: { - _id: "3", - status: 200 } } ] } + [ { + create: { + _id: "uniq-id-1", + status: 201 + } + }, + { + create: { + _id: "uniq-id-2", + status: 201 + } + }, + { + create: { + _id: "uniq-id-3", + status: 206 + } + } ] } */ + const successfulImport = response.items.filter(item => item.create.status === 201); - console.log(`Successfully imported ${response.length} documents`); + console.log(`Successfully imported ${successfulImport} documents`); } catch (error) { console.error(error.message); } From bbb4755c35d1912dabb67a7a8e25964ddb36d529 Mon Sep 17 00:00:00 2001 From: Adrien Maret Date: Mon, 3 Jun 2019 18:11:26 +0200 Subject: [PATCH 2/3] Update src/core/1/api/api-reference/controller-bulk/import/index.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Sébastien Cottinet --- src/core/1/api/api-reference/controller-bulk/import/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/1/api/api-reference/controller-bulk/import/index.md b/src/core/1/api/api-reference/controller-bulk/import/index.md index 012264c4d..f35b1921f 100644 --- a/src/core/1/api/api-reference/controller-bulk/import/index.md +++ b/src/core/1/api/api-reference/controller-bulk/import/index.md @@ -78,7 +78,7 @@ The body must contain a `bulkData` array, detailing the bulk operations to perfo Returns an object containing 2 properties: - `items`: array containing the list of executed queries result, in the same order than in the query - - `errors`: boolean indicating if some error occured during the bulk + - `errors`: boolean indicating if some error occured during the import Each query result contains the following properties: From f61942b37634c114068a5930860b0da50b03b00b Mon Sep 17 00:00:00 2001 From: Adrien Maret Date: Thu, 6 Jun 2019 14:24:06 +0200 Subject: [PATCH 3/3] Update src/sdk/js/6/controllers/bulk/import/snippets/import.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Benoît Vidis --- src/sdk/js/6/controllers/bulk/import/snippets/import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdk/js/6/controllers/bulk/import/snippets/import.js b/src/sdk/js/6/controllers/bulk/import/snippets/import.js index fa5aa1cfe..a0011e997 100644 --- a/src/sdk/js/6/controllers/bulk/import/snippets/import.js +++ b/src/sdk/js/6/controllers/bulk/import/snippets/import.js @@ -34,7 +34,7 @@ try { */ const successfulImport = response.items.filter(item => item.create.status === 201); - console.log(`Successfully imported ${successfulImport} documents`); + console.log(`Successfully imported ${successfulImport.length} documents`); } catch (error) { console.error(error.message); }