diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 210316d84bd4920decaeb127408fd9f8110c97fe..b5111dc1d38d30dcdc1b63fa57db562c352f2f3a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -155,6 +155,13 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } bool isOnlyId = true; auto coll = Collection(collection, executor_); + bool isCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -235,6 +242,13 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); auto coll = Collection(collection, executor_); + bool isCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -286,6 +300,13 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); + bool isCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } if (document.length() + 1 > JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; @@ -321,7 +342,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - if (!coll.IsCollectionExists(errCode)) { + bool isCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { return -E_INVALID_ARGS; } if (filter.empty()) { @@ -433,6 +458,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string ifShowId = true; } auto coll = Collection(collection, executor_); + bool isCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!isCollectionExist) { + return -E_INVALID_ARGS; + } std::lock_guard lock(dbMutex_); if (!coll.FindDocument()) { GLOGE("no corresponding table name"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 17ff76b7b25f45d3f8ba2514a7fa7aeb6cac76fc..fa4c609fb73a674221c569d341519ef3bac13324 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -150,7 +150,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string val = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_NO_DATA); + EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_INVALID_ARGS); } /**