Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Handle emplace + null values.

Kishore Nallanb3f248bd9349
diff --git a/src/validator.cpp b/src/validator.cpp
index 51a7d19c..f814c923 100644
--- a/src/validator.cpp
+++ b/src/validator.cpp
@@ -626,7 +626,7 @@ Option<uint32_t> validator_t::validate_index_in_memory(nlohmann::json& document,
continue;
}
- if((a_field.optional || op == UPDATE || op == EMPLACE) && document.count(field_name) == 0) {
+ if((a_field.optional || op == UPDATE || (op == EMPLACE && is_update)) && document.count(field_name) == 0) {
continue;
}
diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp
index 6def5d1a..98a94f37 100644
--- a/test/collection_nested_fields_test.cpp
+++ b/test/collection_nested_fields_test.cpp
@@ -2578,6 +2578,19 @@ TEST_F(CollectionNestedFieldsTest, EmplaceWithNullValueOnRequiredField) {
ASSERT_TRUE(op.ok());
Collection *coll1 = op.get();
+ auto doc_with_null = R"({
+ "id": "0",
+ "currency": {
+ "eu": null
+ }
+ })"_json;
+
+ auto add_op = coll1->add(doc_with_null.dump(), EMPLACE);
+ ASSERT_FALSE(add_op.ok());
+
+ add_op = coll1->add(doc_with_null.dump(), CREATE);
+ ASSERT_FALSE(add_op.ok());
+
auto doc1 = R"({
"id": "0",
"currency": {
@@ -2585,7 +2598,7 @@ TEST_F(CollectionNestedFieldsTest, EmplaceWithNullValueOnRequiredField) {
}
})"_json;
- auto add_op = coll1->add(doc1.dump(), CREATE);
+ add_op = coll1->add(doc1.dump(), CREATE);
ASSERT_TRUE(add_op.ok());
// now update with null value -- should not be allowed