UNPKG

strapi-plugin-i18n

Version:

This plugin enables to create, to read and to update content in different languages, both from the Admin Panel and from the API

25 lines (18 loc) 769 B
'use strict'; const { migrate } = require('./migrate'); const { areScalarAttributesOnly } = require('./utils'); const batchUpdate = async ({ updatesInfo, model }) => { const updates = updatesInfo.map(({ entriesIdsToUpdate, attributesValues }) => ({ updateMany: { filter: { _id: { $in: entriesIdsToUpdate } }, update: attributesValues }, })); await model.bulkWrite(updates); }; const migrateForMongoose = async ({ model, attributesToMigrate }) => { const onlyScalarAttrs = areScalarAttributesOnly({ model, attributes: attributesToMigrate }); if (onlyScalarAttrs) { await migrate({ model, attributesToMigrate }, { migrateFn: batchUpdate }); } else { await migrate({ model, attributesToMigrate }); } }; module.exports = migrateForMongoose;