fix: on/off tab in home page

This commit is contained in:
Đỗ Minh Nhật
2026-04-11 04:46:33 +07:00
parent 5b96bfeb87
commit e7929568dc
14 changed files with 48 additions and 26 deletions

View File

@@ -0,0 +1,22 @@
require('dotenv').config();
const mongoose = require('mongoose');
const Home = require('../models/home');
mongoose.connect(process.env.MONGODB_URI).then(async () => {
const docs = await Home.find().sort({ updatedAt: -1 }).lean();
console.log('Total docs:', docs.length);
if (docs.length <= 1) {
console.log('Nothing to clean up.');
return;
}
const keep = docs[0];
const idsToDelete = docs.slice(1).map(d => d._id);
await Home.deleteMany({ _id: { $in: idsToDelete } });
console.log('Kept doc:', keep._id, '| hero.enabled:', keep.hero?.enabled);
console.log('Deleted', idsToDelete.length, 'duplicate docs');
await mongoose.disconnect();
});