Does updateZoneKeyRange works with Time Series Collection In Mongodb?

Hi All,
I am trying to create a sharded time series collection and add updateZoneKeyRange as below

 db.createCollection( "test_timeseries", {
            timeseries: {
               timeField: "timeStamp",
               metaField: "metaData",
               granularity: "seconds"
            },
            expireAfterSeconds: 604800
         });

 db.adminCommand({ shardCollection: "test.test_timeseries", key: { "metaData.location": 1 } });
 db.adminCommand({ updateZoneKeyRange: "test.test_timeseries", min: { "metaData.location": 11 }, max: { "metaData.location": 20 }, zone: "rs1" });
 db.adminCommand({ updateZoneKeyRange: "test.test_timeseries", min: { "metaData.location": 1 }, max: { "metaData.location": 10 }, zone: "rs2" });

But the time series collection “test_timeseries” is getting created only on rs1 shard. Also, documents inserted to “test_timeseries” collection are getting inserted into only rs1 irrespective of metaData.location value.

If I execute same commands for regular collection as below

 db.createCollection( "test_regular"});

 db.adminCommand({ shardCollection: "test.test_regular", key: { "metaData.location": 1 } });
 db.adminCommand({ updateZoneKeyRange: "test.test_regular", min: { "metaData.location": 11 }, max: { "metaData.location": 20 }, zone: "rs1" });
 db.adminCommand({ updateZoneKeyRange: "test.test_regular", min: { "metaData.location": 1 }, max: { "metaData.location": 10 }, zone: "rs2" });

Here, for regular collection, “test_regular” collection is getting created on rs1 as well as rs2. Also, documents inserted to “test_regular” collection are getting inserted into rs1 and rs2 shards based on the metaData.location.

Mongodb version:5.0.17

Does updateZoneKeyRange works with Time Series Collection In Mongodb? What is wrong here?

CC: @Kushagra_Kesav

Thanks in advance.

The problem got solved when executed updateZoneKeyRange on bucket collection rather than view.

db.adminCommand({ updateZoneKeyRange: "test.system.buckets.test_regular", min: { "meta.location": 11 }, max: { "meta.location": 20 }, zone: "rs1" });
db.adminCommand({ updateZoneKeyRange: "test.system.buckets.test_regular", min: { "meta.location": 1 }, max: { "meta.location": 10 }, zone: "rs2" });

db.adminCommand({ shardCollection: "test.test_regular", key: { "metaData.location": 1 } });

also updateZoneKeyRange should be called before shardCollection.
Requesting team to document this.

Hi All,
with respect to this documentation

Mongodb version used: 5.0.17

I am trying to shard the time series collection, but it is not getting replicated to other shard members.

sh.shardCollection(
   "test.weather",
   { "metadata.sensorId": 1 },
   {
      timeseries: {
         timeField: "timestamp",
         metaField: "metadata",
         granularity: "hours"
      }
   }
)

db.weather.insertOne( {
   "metadata": { "sensorId": 5578, "type": "temperature" },
   "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
   "temp": 12
} )

Now when I login to each shard, the time series collection is available on only one shard from where it was created. I am connecting to router to create the time series collection.
The above steps works fine for regular collection.

Thanks in advance.

Hi All,
I am trying to shard the time series collection and adding shard zones using below

sh.addShard("<replica_set1>/<rs1_node_1_ip_address>:27018,<rs1_node_2_ip_address>:27018,<rs1_node_3_ip_address>:27018");
sh.addShardToZone("<replica_set1>", "rs1");
sh.addShard("<replica_set2>/<rs2_node_1_ip_address>:27018,<rs2_node_2_ip_address>:27018,<rs2_node_3_ip_address>:27018");
sh.addShardToZone("<replica_set2>", "rs2");

//enabling sharding for test.collection1.

sh.enableSharding("test");
sh.shardCollection("test.collection1", {key:1});
sh.updateZoneKeyRange("test.collection1", { key: 1 }, { key: 5 }, "rs1");
sh.updateZoneKeyRange("test.collection1", { key: 6 }, { key: 10 }, "rs2");

This works fine for if test.collection1 is a regular collection, documents are stored in different shards based on the zone key range.
But if test.collection1 is a time series collections, all documents are getting stored in rs1 only, irrespective of value of key.

Is it that updateZoneKeyRange does not work with time series collection?
how to achieve that?

Thanks in advance.

Thanks for flagging this; we have a warning on 5.0 rapid releases around not supporting zones for sharded time series collections, but not 5.0.

We’re looking into it now.

Thank you for your reply.
I would like to understand your reply.
I am using 5.0.17 version, which supports time series collection sharding as per your documentation.

  1. Does zones supports for sharded time series collection with mongodb version 5.0.17? For me, updateZoneKeyRange executing on system.buckets. worked as documents are saved based on the keys range. Is that correct way to do it. Or we shall not execute updateZoneKeyRange on system.buckets.?
  2. I am planning to upgrade mongodb to version 6.0. Does zones support for sharded time series collection with mongodb version 6.0?
  3. With Mongodb 6.0 version, shall I continue to execute updateZoneKeyRange on system.buckets. or it will work with updateZoneKeyRange on time series collection directly?

Thank you in advance.

Dear team,
Can you please recommend here ?

Thank You

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.