All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scripts.3.17.0.api-keys-cleanup.js Maven / Gradle / Ivy

The newest version!
/**
 * This script should be run before upgrading in order to avoid any issue
 * linked to https://github.com/spring-projects/spring-data-mongodb/issues/2350$
 * while running the ApiKeySubscriptionUpgrader
 */

// Override this variable if you use prefix
const prefix = "";

function unsetUndefined(doc) {
    return Object.keys(doc).some((k, i) => {
        if (doc[k] === undefined) {
            print("found an undefined field on API Key", doc._id, k, "will be unset");
            delete doc[k];
            return true;
        }
    });
}

db.getCollection(`${prefix}keys`)
    .find({})
    .forEach((doc) => {
        const changed = unsetUndefined(doc);
        if (changed) {
            db.getCollection(`${prefix}keys`).replaceOne({ _id: doc._id }, doc);
        }
    });




© 2015 - 2024 Weber Informatics LLC | Privacy Policy