- aggiornamento Cataloghi
- Gestione delle versioni del prodotto ("Nuovi","Usati","Epub", ecc..)
This commit is contained in:
@@ -88,6 +88,9 @@ const productInfoSchema = new Schema({
|
||||
checkout_link: {
|
||||
type: String,
|
||||
},
|
||||
versioneGM: {
|
||||
type: String,
|
||||
},
|
||||
img2: {
|
||||
type: String,
|
||||
},
|
||||
@@ -114,9 +117,9 @@ const productInfoSchema = new Schema({
|
||||
date_publishing: {
|
||||
type: Date,
|
||||
},
|
||||
productType: {
|
||||
productTypes: [{
|
||||
type: Number,
|
||||
},
|
||||
}],
|
||||
|
||||
});
|
||||
|
||||
@@ -215,6 +218,51 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
|
||||
module.exports.getProductByCode = function (idapp, code) {
|
||||
return productInfo.findAllIdApp(idapp, code);
|
||||
}
|
||||
module.exports.correggiProductTypes = async function() {
|
||||
const ProductInfo = this;
|
||||
const bulkOps = [];
|
||||
|
||||
try {
|
||||
// Fase di aggregazione
|
||||
const cursor = ProductInfo.aggregate([
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
productType: 1,
|
||||
productTypes: [{ $ifNull: ['$productType', 10] }]
|
||||
}
|
||||
}
|
||||
]).cursor({ batchSize: 1000 }).exec();
|
||||
|
||||
// Itera attraverso ogni documento utilizzando il cursore
|
||||
for await (const doc of cursor) {
|
||||
bulkOps.push({
|
||||
updateOne: {
|
||||
filter: { _id: doc._id },
|
||||
update: {
|
||||
$set: { productTypes: doc.productTypes },
|
||||
$unset: { productType: "" }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Scrivi i batch di operazioni ogni 1000 documenti
|
||||
if (bulkOps.length === 1000) {
|
||||
await ProductInfo.bulkWrite(bulkOps);
|
||||
bulkOps.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Scrivi eventuali operazioni rimanenti
|
||||
if (bulkOps.length > 0) {
|
||||
await ProductInfo.bulkWrite(bulkOps);
|
||||
}
|
||||
|
||||
console.log('ProductInfo.productType converted to productTypes array and saved');
|
||||
} catch (err) {
|
||||
console.error('Error converting ProductInfo.productType:', err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.createIndexes((err) => {
|
||||
if (err) throw err;
|
||||
|
||||
Reference in New Issue
Block a user