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

[SERVER] Script not working in "indexes-configured-using-nan"

      Summary

      The script suggested in https://www.mongodb.com/docs/v5.0/tutorial/expire-data/#indexes-configured-using-nan is not working.

      Motivation

      Who is the affected end user?

      All users who try to run the script are affected. If you run as-is you will see the error:

       

      replset [direct: primary] percona> getNaNIndexes();
      MongoServerError: Namespace local.system.tenantMigration.oplogView is a view, not a collection 

       

      How does this affect the end user?

      Users cannot check their TTL index has any NaN value.

      Suggested Fix

      function getNaNIndexes() {
        const nan_index = [];  const dbs = db.adminCommand({ listDatabases: 1 }).databases;  dbs.forEach((d) => {
          if (d.name != 'local'){
            const listCollCursor = db
              .getSiblingDB(d.name)
              .runCommand({ listCollections: 1 }).cursor;      const collDetails = {
              db: listCollCursor.ns.split(".$cmd")[0],
              colls: listCollCursor.firstBatch.map((c) => c.name),
            };      collDetails.colls.forEach((c) =>
              db
                .getSiblingDB(collDetails.db)
                .getCollection(c)
                .getIndexes()
                .forEach((entry) => {
                  if (Object.is(entry.expireAfterSeconds, NaN)) {
                    nan_index.push({ ns: `${collDetails.db}.${c}`, index: entry });
                  }
                })
            );
            }
        });  return nan_index;
      };getNaNIndexes(); 

            Assignee:
            jeffrey.allen@mongodb.com Jeffrey Allen
            Reporter:
            vgrippa@gmail.com Vinicius Grippa
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              16 weeks, 1 day ago