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

scripts.3.0.2.1-rename-view-in-category.js Maven / Gradle / Ivy

There is a newer version: 4.5.2
Show newest version
print('In apis collection, \'views\' becomes \'categories\'');
db.apis.updateMany( {}, { $rename: { 'views': 'categories' } } );

print('Rename \'views\' collection in \'categories\'');
db.views.renameCollection('categories');

print('Change view links to category links');
db.pages.updateMany(
  { type: 'LINK', 'configuration.resourceType': 'view'},
  { $set: { 'configuration.resourceType': 'category' } }
);

print('Change parameters keys');
db.parameters.find({ _id: {$in: ['portal.apis.viewMode.enabled','portal.apis.apiheader.showviews.enabled','api.quality.metrics.views.weight']}}).forEach( param => {
    let newId = '';
    let oldId = param._id;
    if (param._id === 'portal.apis.viewMode.enabled') {
        newId = 'portal.apis.categoryMode.enabled';
    } else if (param._id === 'portal.apis.apiheader.showviews.enabled') {
        newId = 'portal.apis.apiheader.showcategories.enabled';
    } else if (param._id === 'api.quality.metrics.views.weight') {
        newId = 'api.quality.metrics.categories.weight';
    }
    if (newId) {
        param._id = newId;
        db.parameters.insertOne(param);
        db.parameters.deleteOne({_id: oldId});
    }
});

print ('Update Audit logs to replace VIEW with CATEGORY');
db.audits.find({event: /VIEW/}).forEach(audit => {
  audit.event = audit.event.replace('VIEW', 'CATEGORY');
  audit.properties.CATEGORY = audit.properties.VIEW;
  delete audit.properties.VIEW;
  db.audits.replaceOne({ _id: audit._id }, audit);
});

print ('Update events payloads');
db.events.find({payload: /views/}).forEach( e => {
    e.payload=e.payload.replace('"views"','"categories"');
    db.events.replaceOne({ _id: e._id }, e);
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy