diff --git a/arangod/Utils/Transaction.cpp b/arangod/Utils/Transaction.cpp index 7e90c367c8..1a14513840 100644 --- a/arangod/Utils/Transaction.cpp +++ b/arangod/Utils/Transaction.cpp @@ -141,7 +141,7 @@ static OperationResult DBServerResponseBad(std::shared_ptr resultB } //////////////////////////////////////////////////////////////////////////////// -/// @brief Insert an errror reported instead of the new document +/// @brief Insert an error reported instead of the new document //////////////////////////////////////////////////////////////////////////////// static void createBabiesError(VPackBuilder& builder, @@ -164,6 +164,15 @@ static void createBabiesError(VPackBuilder& builder, } } +static OperationResult EmptyResult(bool waitForSync) { + VPackBuilder resultBuilder; + resultBuilder.openArray(); + resultBuilder.close(); + std::unordered_map errorCounter; + return OperationResult(resultBuilder.steal(), nullptr, "", TRI_ERROR_NO_ERROR, + waitForSync, errorCounter); +} + //////////////////////////////////////////////////////////////////////////////// /// @brief sort ORs for the same attribute so they are in ascending value /// order. this will only work if the condition is for a single attribute @@ -1774,6 +1783,9 @@ OperationResult Transaction::insert(std::string const& collectionName, // must provide a document object or an array of documents THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } + if (value.isArray() && value.length() == 0) { + return EmptyResult(options.waitForSync); + } // Validate Edges OperationOptions optionsCopy = options; @@ -2024,6 +2036,9 @@ OperationResult Transaction::update(std::string const& collectionName, // must provide a document object or an array of documents THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } + if (newValue.isArray() && newValue.length() == 0) { + return EmptyResult(options.waitForSync); + } OperationOptions optionsCopy = options; @@ -2078,6 +2093,9 @@ OperationResult Transaction::replace(std::string const& collectionName, // must provide a document object or an array of documents THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } + if (newValue.isArray() && newValue.length() == 0) { + return EmptyResult(options.waitForSync); + } OperationOptions optionsCopy = options; @@ -2338,6 +2356,9 @@ OperationResult Transaction::remove(std::string const& collectionName, // must provide a document object or an array of documents THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID); } + if (value.isArray() && value.length() == 0) { + return EmptyResult(options.waitForSync); + } OperationOptions optionsCopy = options; diff --git a/js/common/tests/shell/shell-document-babies.js b/js/common/tests/shell/shell-document-babies.js index 879fa13c06..d6f1fde22e 100644 --- a/js/common/tests/shell/shell-document-babies.js +++ b/js/common/tests/shell/shell-document-babies.js @@ -882,6 +882,32 @@ function CollectionDocumentSuiteBabies() { assertEqual(ERRORS.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, err6.errorNum); } + }, + + //////////////////////////////////////////////////////////////////////////////// + /// @brief test insert/replace/update/remove with empty lists + //////////////////////////////////////////////////////////////////////////////// + + testEmptyBabiesList: function() { + // Insert + let result = collection.insert([]); + assertTrue(Array.isArray(result)); + assertEqual(result.length, 0); + + // Update + result = collection.update([], []); + assertTrue(Array.isArray(result)); + assertEqual(result.length, 0); + + // Replace + result = collection.replace([], []); + assertTrue(Array.isArray(result)); + assertEqual(result.length, 0); + + // Remove + result = collection.remove([]); + assertTrue(Array.isArray(result)); + assertEqual(result.length, 0); } };