From 06fe0529be0c93eb1178907d52530fb315ce3370 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Wed, 5 Jun 2024 10:40:38 +0200 Subject: [PATCH] Fixed issue #1557 --- CHANGES_NEXT_RELEASE | 1 + src/lib/orionld/mongoc/mongocEntitiesQuery.cpp | 12 ++++++++++++ ...gsild_new_subscription_patch_and_propagation.test | 8 ++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index b7f170a829..4c64142163 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -2,6 +2,7 @@ * #1535: Ignore Subscription::q when matching subscriptions for deletion of an entity * #1542: Array Reduction (arrays of one single element are "flattened" to that very element) * #1551: format=simplified for distribute GET /entities gave Normalized for entities from other brokers + * #1557: Cannot count entities if geo query with $near - mongodb doesn't allow it * #1573: pagination not working when entities have the exact same creation date (sort also by entity id) * #1583: If a 'q' contains an ampersand, that ampersand needs to be forwarded as a semicolon * #1593: Modify the type of an entity in a Replace operation (only working in legacy mode) diff --git a/src/lib/orionld/mongoc/mongocEntitiesQuery.cpp b/src/lib/orionld/mongoc/mongocEntitiesQuery.cpp index fa5d65dd86..653ed9954b 100644 --- a/src/lib/orionld/mongoc/mongocEntitiesQuery.cpp +++ b/src/lib/orionld/mongoc/mongocEntitiesQuery.cpp @@ -777,6 +777,18 @@ KjNode* mongocEntitiesQuery { if (geoFilter(&mongoFilter, geoInfoP) == false) return NULL; + + // + // NOTE + // Counting doesn't work with $near|$nearSphere + // Must cancel the count in case it's requested, if it's a geo query with $near + // + if ((geoInfoP->georel == GeorelNear) && (countP != NULL)) + { + LM_W(("Cannot count entities if georel is 'near'. MongoDB doesn't allow it")); + *countP = -2; // Mark the 'absense' of a count + countP = NULL; // This inhibits the count + } } bson_append_document(&options, "projection", 10, &projection); diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_new_subscription_patch_and_propagation.test b/test/functionalTest/cases/0000_ngsild/ngsild_new_subscription_patch_and_propagation.test index 293b6bff73..1d213f306e 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_new_subscription_patch_and_propagation.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_new_subscription_patch_and_propagation.test @@ -142,7 +142,7 @@ payload='{ "accept": "application/json" } }, - "expiresAt": "2024-06-01T10:00:00.123Z", + "expiresAt": "2034-06-01T10:00:00.123Z", "throttling": 5.5, "lang": "es" }' @@ -363,7 +363,7 @@ Link: ; rel="h "type": "T" } ], - "expiresAt": "2024-06-01T10:00:00.123Z", + "expiresAt": "2034-06-01T10:00:00.123Z", "geoQ": { "coordinates": "5,5", "geometry": "Point", @@ -438,7 +438,7 @@ MongoDB server version: REGEX(.*) "ldContext" : "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld", "ldQ" : "https://uri=etsi=org/ngsi-ld/default-context/a.value>12", "name" : "New name", - "expiration" : 1717236000.123 + "expiration" : 2032768800.123 } bye @@ -464,7 +464,7 @@ Link: ; rel="h "type": "T" } ], - "expiresAt": "2024-06-01T10:00:00.123Z", + "expiresAt": "2034-06-01T10:00:00.123Z", "geoQ": { "coordinates": [ 5,