Skip to content

Commit

Permalink
(DOCS-16562): Fix code for finding NaN indexes to work on Atlas (#5984)…
Browse files Browse the repository at this point in the history
… (#5997)
  • Loading branch information
jeff-allen-mongo authored Jan 25, 2024
1 parent 5f7f93b commit 937e434
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions source/tutorial/expire-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,37 +299,39 @@ To avoid problems, either drop or correct any misconfigured TTL indexes.
.. code-block:: javascript

function getNaNIndexes() {
const nan_index = [];

const dbs = db.adminCommand({ listDatabases: 1 }).databases;

dbs.forEach((d) => {
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;
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();
getNaNIndexes();

.. step:: Correct misconfigured indexes.

Expand All @@ -339,4 +341,3 @@ To avoid problems, either drop or correct any misconfigured TTL indexes.
As an alternative, you can :dbcommand:`drop <dropIndexes>` any
misconfigured TTL indexes and recreate them later using the
:dbcommand:`createIndexes` command.

0 comments on commit 937e434

Please sign in to comment.