Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16734

[Server] Clarification on creating partial index on metaField and timeField.

      Hello Team,

      On the limitation page, we mention that : You can create partial indexes on every field except metaField and timeField.

      In the documentation, it says “You can Add partial on the metaField”

      In the documentation, it says “You can Add a partial filter expression on the metaField”.

      This is incorrect and there is a mismatch in these documentations. In short, we can create partial indexes on both metaField and timeField as well. This needs to be updated in all of the above documentations.

      Proof of working:
      I have performed the testing in 6.0.14 version.

      Connecting to: mongodb+srv://<credentials>@cluster0.f1qgt.mongodb.net/?appName=mongosh+1.10.5
      Using MongoDB: 6.0.14 (API Version 1)
      Using Mongosh: 1.10.5
       
      For mongosh info see: https://docs.mongodb.com/mongodb-shell/
      Atlas atlas-u3uk23-shard-0 [primary] test> db.createCollection("sensor4", {
      ...   timeseries: {
      ...     timeField: "timestamp",
      ...     metaField: "metadata",
      ...     granularity: "minutes",
      ...   }, expireAfterSeconds : 60
      ... });
      { ok: 1 }
      Atlas atlas-u3uk23-shard-0 [primary] test> show collections;
      sensor4                     [time-series]
      system.buckets.sensor4
      system.views
      Atlas atlas-u3uk23-shard-0 [primary] test> db.sensor4.createIndex(   { "metadata.temperature" : 1 },   { partialFilterExpression: { temperature: { $gt: 5 } } })
      metadata.temperature_1
      Atlas atlas-u3uk23-shard-0 [primary] test> db.sensor4.createIndex(   { "timestamp" : 1 },   { partialFilterExpression: { timestamp: { $gt: new Date("2022-01-01T00:00:00.000Z") } } })
      timestamp_1
      Atlas atlas-u3uk23-shard-0 [primary] test> db.sensor4.createIndex(   { "measurements" : 1 },   { partialFilterExpression: { measurements: { $gt: 5 } } })
      measurements_1
      Atlas atlas-u3uk23-shard-0 [primary] test> db.sensor4.getIndexes();
      [
        {
          v: 2,
          key: { 'metadata.temperature': 1 },
          name: 'metadata.temperature_1',
          partialFilterExpression: { temperature: { '$gt': 5 } }
        },
        {
          v: 2,
          key: { timestamp: 1 },
          name: 'timestamp_1',
          partialFilterExpression: { timestamp: { '$gt': ISODate("2022-01-01T00:00:00.000Z") } }
        },
        {
          v: 2,
          key: { measurements: 1 },
          name: 'measurements_1',
          partialFilterExpression: { measurements: { '$gt': 5 } }
        }
      ] 

      Please let me know if any further clarification is needed.

      Regards,
      Anantha Krishna Pai

            Assignee:
            jeffrey.allen@mongodb.com Jeffrey Allen
            Reporter:
            anantha.pai@mongodb.com Anantha Krishna Pai
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              3 weeks ago