[DOCS-16562] [SERVER] Script not working in "indexes-configured-using-nan" Created: 04/Jan/24  Updated: 29/Jan/24  Resolved: 25/Jan/24

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: Server_Docs_[20240129]

Type: Task Priority: Major - P3
Reporter: Vinicius Grippa Assignee: Jeffrey Allen
Resolution: Fixed Votes: 0
Labels: bug, top250
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

URL(s): https://www.mongodb.com/docs/manual/tutorial/expire-data/#indexes-configured-using-nan
Participants:
Days since reply: 4 weeks, 6 days ago

 Description   

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(); 


Generated at Thu Feb 08 08:15:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.