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

Should forbid illegal form of TTL indexes

    • Fully Compatible
    • ALL
    • Hide
      > db.expire.ensureIndex({b:1, ts:1,_id:1}, {expireAfterSeconds: 30})
      > db.expire.ensureIndex({ts:1, expireAfterSeconds: 30})
      > db.expire.getIndexes()
      [
      	{
      		"v" : 1,
      		"key" : {
      			"_id" : 1
      		},
      		"ns" : "ttl.expire",
      		"name" : "_id_"
      	},
      	{
      		"v" : 1,
      		"key" : {
      			"ts" : 1,
      			"expireAfterSeconds" : 30
      		},
      		"ns" : "ttl.expire",
      		"name" : "ts_1_expireAfterSeconds_30"
      	},
      	{
      		"v" : 1,
      		"key" : {
      			"ts" : 1
      		},
      		"ns" : "ttl.expire",
      		"name" : "ts_1",
      		"expireAfterSeconds" : 30
      	},
      	{
      		"v" : 1,
      		"key" : {
      			"b" : 1,
      			"ts" : 1,
      			"_id" : 1
      		},
      		"ns" : "ttl.expire",
      		"name" : "b_1_ts_1__id_1",
      		"expireAfterSeconds" : 30
      	}
      ]
      
      Show
      > db.expire.ensureIndex({b:1, ts:1,_id:1}, {expireAfterSeconds: 30}) > db.expire.ensureIndex({ts:1, expireAfterSeconds: 30}) > db.expire.getIndexes() [ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "ttl.expire" , "name" : "_id_" }, { "v" : 1, "key" : { "ts" : 1, "expireAfterSeconds" : 30 }, "ns" : "ttl.expire" , "name" : "ts_1_expireAfterSeconds_30" }, { "v" : 1, "key" : { "ts" : 1 }, "ns" : "ttl.expire" , "name" : "ts_1" , "expireAfterSeconds" : 30 }, { "v" : 1, "key" : { "b" : 1, "ts" : 1, "_id" : 1 }, "ns" : "ttl.expire" , "name" : "b_1_ts_1__id_1" , "expireAfterSeconds" : 30 } ]
    • Storage NYC 2019-05-20

      I can create a TTL index with multiple fields and it succeeds. It's not until the TTL thread runs that I get an error in the logs:
      Mon Jul 1 12:22:13.189 [TTLMonitor] ERROR: key for ttl index can only have 1 field

      The time to show error (and maybe disallow the index creation?) is when an illegal index is specified.

      In a related case, user incorrectly specifying expireAfterSeconds as the last field of the index also should get an error rather than the value other than 1 or -1 for field name being accepted.

            Assignee:
            gregory.wlodarek@mongodb.com Gregory Wlodarek
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: