Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-55239

Support 2dsphere index on time-series collection metadata fields

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Storage
    • None
    • Execution Team 2021-07-12, Execution Team 2021-07-26, Execution Team 2021-08-09
    • 70

      Because metadata does not vary within a bucket, geo indexes on metadata can use an ordinary geo index on the time-series buckets collection.

      For example,

      {
      	createIndexes: “abc”,
      	indexes: [ { key: { “metaFieldName.a” : "2dsphere" } } ]
      }
      
      

      will become

      {
      	createIndexes: “system.buckets.abc”,
      	indexes: [ { key: { “meta.a” : "2dsphere" } } ]
      }
      

       

       

       

      JS test code

      assert.eq(1,
                timeseriescoll.aggregate([
                    {$geoNear: {
                        near: {type: "Point", coordinates: [40.4, -70.4]},
                        distanceField: "dist",
                        spherical: true
                    }},
                    {$limit: 1}
                ]).toArray().length,
                "Failed to use 2dsphere index: " + tojson(twoDSphereBucketsIndexSpec));
      

      JS test logs

      [js_test:timeseries_special_indexes] assert: command failed: {
      [js_test:timeseries_special_indexes] 	"ok" : 0,
      [js_test:timeseries_special_indexes] 	"errmsg" : "$geoNear is only valid as the first stage in a pipeline.",
      [js_test:timeseries_special_indexes] 	"code" : 40602,
      [js_test:timeseries_special_indexes] 	"codeName" : "Location40602"
      [js_test:timeseries_special_indexes] } with original command request: {
      [js_test:timeseries_special_indexes] 	"aggregate" : "timeseries_special_indexes_coll",
      [js_test:timeseries_special_indexes] 	"pipeline" : [
      [js_test:timeseries_special_indexes] 		{
      [js_test:timeseries_special_indexes] 			"$geoNear" : {
      [js_test:timeseries_special_indexes] 				"near" : {
      [js_test:timeseries_special_indexes] 					"type" : "Point",
      [js_test:timeseries_special_indexes] 					"coordinates" : [
      [js_test:timeseries_special_indexes] 						40.4,
      [js_test:timeseries_special_indexes] 						-70.4
      [js_test:timeseries_special_indexes] 					]
      [js_test:timeseries_special_indexes] 				},
      [js_test:timeseries_special_indexes] 				"distanceField" : "dist",
      [js_test:timeseries_special_indexes] 				"spherical" : true
      [js_test:timeseries_special_indexes] 			}
      [js_test:timeseries_special_indexes] 		},
      [js_test:timeseries_special_indexes] 		{
      [js_test:timeseries_special_indexes] 			"$limit" : 1
      [js_test:timeseries_special_indexes] 		}
      [js_test:timeseries_special_indexes] 	],
      [js_test:timeseries_special_indexes] 	"cursor" : {
      [js_test:timeseries_special_indexes]
      [js_test:timeseries_special_indexes] 	},
      [js_test:timeseries_special_indexes] 	"lsid" : {
      [js_test:timeseries_special_indexes] 		"id" : UUID("073e7905-4789-4ab9-88f2-45fb46cb2f97")
      [js_test:timeseries_special_indexes] 	}
      [js_test:timeseries_special_indexes] } on connection: connection to localhost:50190 : aggregate failed
      [js_test:timeseries_special_indexes] _getErrorWithCode@src/mongo/shell/utils.js:25:13
      [js_test:timeseries_special_indexes] doassert@src/mongo/shell/assert.js:18:14
      [js_test:timeseries_special_indexes] _assertCommandWorked@src/mongo/shell/assert.js:719:17
      [js_test:timeseries_special_indexes] assert.commandWorked@src/mongo/shell/assert.js:811:16
      [js_test:timeseries_special_indexes] DB.prototype._runAggregate@src/mongo/shell/db.js:268:5
      [js_test:timeseries_special_indexes] DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1056:12
      [js_test:timeseries_special_indexes] @jstests/core/timeseries/timeseries_special_indexes.js:210:11
      [js_test:timeseries_special_indexes] @jstests/core/timeseries/timeseries_special_indexes.js:18:2
      [js_test:timeseries_special_indexes] uncaught exception: Error: command failed: {
      [js_test:timeseries_special_indexes] 	"ok" : 0,
      [js_test:timeseries_special_indexes] 	"errmsg" : "$geoNear is only valid as the first stage in a pipeline.",
      [js_test:timeseries_special_indexes] 	"code" : 40602,
      [js_test:timeseries_special_indexes] 	"codeName" : "Location40602"
      [js_test:timeseries_special_indexes] } with original command request: {
      [js_test:timeseries_special_indexes] 	"aggregate" : "timeseries_special_indexes_coll",
      [js_test:timeseries_special_indexes] 	"pipeline" : [
      [js_test:timeseries_special_indexes] 		{
      [js_test:timeseries_special_indexes] 			"$geoNear" : {
      [js_test:timeseries_special_indexes] 				"near" : {
      [js_test:timeseries_special_indexes] 					"type" : "Point",
      [js_test:timeseries_special_indexes] 					"coordinates" : [
      [js_test:timeseries_special_indexes] 						40.4,
      [js_test:timeseries_special_indexes] 						-70.4
      [js_test:timeseries_special_indexes] 					]
      [js_test:timeseries_special_indexes] 				},
      [js_test:timeseries_special_indexes] 				"distanceField" : "dist",
      [js_test:timeseries_special_indexes] 				"spherical" : true
      [js_test:timeseries_special_indexes] 			}
      [js_test:timeseries_special_indexes] 		},
      [js_test:timeseries_special_indexes] 		{
      [js_test:timeseries_special_indexes] 			"$limit" : 1
      [js_test:timeseries_special_indexes] 		}
      [js_test:timeseries_special_indexes] 	],
      [js_test:timeseries_special_indexes] 	"cursor" : {
      [js_test:timeseries_special_indexes]
      [js_test:timeseries_special_indexes] 	},
      [js_test:timeseries_special_indexes] 	"lsid" : {
      [js_test:timeseries_special_indexes] 		"id" : UUID("073e7905-4789-4ab9-88f2-45fb46cb2f97")
      [js_test:timeseries_special_indexes] 	}
      [js_test:timeseries_special_indexes] } on connection: connection to localhost:50190 : aggregate failed :
      [js_test:timeseries_special_indexes] _getErrorWithCode@src/mongo/shell/utils.js:25:13
      [js_test:timeseries_special_indexes] doassert@src/mongo/shell/assert.js:18:14
      [js_test:timeseries_special_indexes] _assertCommandWorked@src/mongo/shell/assert.js:719:17
      [js_test:timeseries_special_indexes] assert.commandWorked@src/mongo/shell/assert.js:811:16
      [js_test:timeseries_special_indexes] DB.prototype._runAggregate@src/mongo/shell/db.js:268:5
      [js_test:timeseries_special_indexes] DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1056:12
      [js_test:timeseries_special_indexes] @jstests/core/timeseries/timeseries_special_indexes.js:210:11
      [js_test:timeseries_special_indexes] @jstests/core/timeseries/timeseries_special_indexes.js:18:2
      [js_test:timeseries_special_indexes] failed to load: jstests/core/timeseries/timeseries_special_indexes.js
      

      Note: the same query on the corresponding buckets collection works fine, so the index is created via the time-series collection, we just can't use it.

            Assignee:
            dan.larkin-york@mongodb.com Dan Larkin-York
            Reporter:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: