Don't validate the id field.

This commit is contained in:
Kishore Nallan 2021-07-07 20:44:21 +05:30
parent 184ed43727
commit 614f7a9f61
2 changed files with 22 additions and 0 deletions

View File

@ -311,6 +311,10 @@ Option<uint32_t> 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;
}

View File

@ -294,6 +294,24 @@ TEST_F(CollectionSpecificTest, PrefixWithTypos2) {
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSpecificTest, ImportDocumentWithIntegerID) {
std::vector<field> 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<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false),};