From 9a18b279d302d5aad79435bc2fa465dcd6692e6a Mon Sep 17 00:00:00 2001 From: Allison Easton Date: Tue, 15 Feb 2022 08:56:46 +0000 Subject: SERVER-63617 Invalid 2D sphere documents do not throw BadValue --- .../timeseries/timeseries_metric_index_2dsphere.js | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/jstests/core/timeseries/timeseries_metric_index_2dsphere.js b/jstests/core/timeseries/timeseries_metric_index_2dsphere.js index 5997a8254e3..a7fece34c53 100644 --- a/jstests/core/timeseries/timeseries_metric_index_2dsphere.js +++ b/jstests/core/timeseries/timeseries_metric_index_2dsphere.js @@ -92,12 +92,15 @@ TimeseriesTest.run((insert) => { assert.commandWorked(insert(timeseriescoll, twoDSphereDocs), 'Failed to insert twoDSphereDocs: ' + tojson(twoDSphereDocs)); - const invalidDocs = [ - { - _id: 6, - [timeFieldName]: ISODate(), - location: {type: "Polygon", coordinates: [[0, 0], [1, 0], [1, 1], [0, 0]]} - }, + // Test invalid documents + const docWithInvalidCoordinates = { + _id: 6, + [timeFieldName]: ISODate(), + location: {type: "Polygon", coordinates: [[0, 0], [1, 0], [1, 1], [0, 0]]} + }; + // Can't extract geo keys: GeoJSON coordinates must be an array + assert.commandFailedWithCode(insert(timeseriescoll, docWithInvalidCoordinates), 183934); + const docsWithTypeNotPoint = [ { _id: 7, [timeFieldName]: ISODate(), @@ -109,10 +112,10 @@ TimeseriesTest.run((insert) => { location: {type: "LineString", coordinates: [[0, 0], [1, 0], [1, 1], [0, 0]]} } ]; - for (const invalidDoc in invalidDocs) { - assert.commandFailedWithCode(assert.throws(() => insert(timeseriescoll, invalidDoc)), - ErrorCodes.BadValue); - } + docsWithTypeNotPoint.forEach((invalidDoc) => { + // Time-series collections '2dsphere' indexes only support point data + assert.commandFailedWithCode(insert(timeseriescoll, invalidDoc), 183493); + }); // Assert that geoWithin queries use the index. const geoWithinPlan = -- cgit v1.2.1