diff --git a/src/index.cpp b/src/index.cpp index 7513a7b7..89d93954 100644 --- a/src/index.cpp +++ b/src/index.cpp @@ -6614,7 +6614,9 @@ void Index::remove_field(uint32_t seq_id, nlohmann::json& document, const std::s options.set_index_contains_points_only(true); S2RegionTermIndexer indexer(options); - const std::vector>& latlongs = search_field.is_single_geopoint() ? + // Geopoint field that is part of an object array will be marked as `geopoint[]` type, but it should be treated + // as a `geopoint` type. + const std::vector>& latlongs = search_field.is_single_geopoint() || search_field.nested_array ? std::vector>{document[field_name].get>()} : document[field_name].get>>(); diff --git a/test/collection_nested_fields_test.cpp b/test/collection_nested_fields_test.cpp index a205d6b1..3c65b44f 100644 --- a/test/collection_nested_fields_test.cpp +++ b/test/collection_nested_fields_test.cpp @@ -2064,6 +2064,36 @@ TEST_F(CollectionNestedFieldsTest, NestedFieldWithGeopointArray) { ASSERT_EQ("Field `addresses.geoPoint` must be an array of geopoint.", create_op.error()); } +TEST_F(CollectionNestedFieldsTest, ObjectArrayWithGeopoint) { + nlohmann::json schema = R"({ + "name": "coll1", + "enable_nested_fields": true, + "fields": [ + {"name": "addresses", "type": "object[]"}, + {"name": "addresses.geoPoint", "type": "geopoint[]"} + ] + })"_json; + + auto op = collectionManager.create_collection(schema); + ASSERT_TRUE(op.ok()); + Collection* coll1 = op.get(); + + auto doc1 = R"({"addresses": [{"geoPoint": [19.07283, 72.88261]}] })"_json; + auto add_op = coll1->add(doc1.dump(), CREATE); + ASSERT_TRUE(add_op.ok()); + + auto results = coll1->search("*", {}, "addresses.geoPoint: (19.07, 72.882, 1 mi)", + {}, {}, {0}, 10, 1, FREQUENCY).get(); + ASSERT_EQ(1, results["found"]); + + auto remove_op = coll1->remove("0"); + ASSERT_TRUE(remove_op.ok()); + + results = coll1->search("*", {}, "addresses.geoPoint: (19.07, 72.882, 1 mi)", + {}, {}, {0}, 10, 1, FREQUENCY).get(); + ASSERT_EQ(0, results["found"]); +} + TEST_F(CollectionNestedFieldsTest, NestedFieldWithGeopoint) { nlohmann::json schema = R"({ "name": "coll1",