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

scripts.3.12.0.api-keys-migration.js Maven / Gradle / Ivy

The newest version!
// Override this variable if you use prefix
const prefix = '';

print(`Add 'key' and 'api' columns in 'keys' table`);

const keys = db.getCollection(`${prefix}keys`);
const subscriptions = db.getCollection(`${prefix}subscriptions`);

keys.find({}).forEach((key) => {
    subscriptions.find({_id: key.subscription}).forEach((subscription) => {
        key.key = key._id;
        key.api = subscription.api;
        keys.replaceOne({ _id: key._id }, key);
    });
});

print(`Create new indexes in 'keys' table`);

keys.createIndex( { "key" : 1 } );
keys.createIndex( { "key" : 1, "api" : 1 } );
keys.reIndex();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy