From 614f7a9f61d7cbf83d3e5b3ea7200e90efc7b703 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Wed, 7 Jul 2021 20:44:21 +0530 Subject: [PATCH] Don't validate the id field. --- src/index.cpp | 4 ++++ test/collection_specific_test.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/index.cpp b/src/index.cpp index b2a9ab5a..43a0b9e6 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -311,6 +311,10 @@ Option Index::validate_index_in_memory(nlohmann::json& document, uint3 const std::string& field_name = field_pair.first; const field& a_field = field_pair.second; + if(field_name == "id") { + continue; + } + if((a_field.optional || op == UPDATE) && document.count(field_name) == 0) { continue; } diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cpp index 6ce707a6..5d9ad008 100644 --- a/test/collection_specific_test.cpp +++ b/test/collection_specific_test.cpp @@ -294,6 +294,24 @@ TEST_F(CollectionSpecificTest, PrefixWithTypos2) { collectionManager.drop_collection("coll1"); } +TEST_F(CollectionSpecificTest, ImportDocumentWithIntegerID) { + std::vector fields = {field("title", field_types::STRING, false), + field("points", field_types::INT32, false),}; + + Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get(); + + nlohmann::json doc1; + doc1["id"] = 100; + doc1["title"] = "East India House on Wednesday evening"; + doc1["points"] = 100; + + auto add_op = coll1->add(doc1.dump()); + ASSERT_FALSE(add_op.ok()); + ASSERT_EQ("Document's `id` field should be a string.", add_op.error()); + + collectionManager.drop_collection("coll1"); +} + TEST_F(CollectionSpecificTest, CreateManyCollectionsAndDeleteOneOfThem) { std::vector fields = {field("title", field_types::STRING, false), field("points", field_types::INT32, false),};