✨ using await for the first time ✨
This commit is contained in:
parent
f196c4ebf8
commit
434ee8e013
1 changed files with 20 additions and 4 deletions
|
@ -24,12 +24,28 @@ mongoose.connection.on('error', () => {
|
|||
// },
|
||||
// });
|
||||
|
||||
const CHUNK = 1000;
|
||||
Project.count({})
|
||||
.exec().then((err, count) => {
|
||||
console.log(err);
|
||||
console.log(count);
|
||||
.exec().then((numProjects) => {
|
||||
console.log(numProjects);
|
||||
for (let i = 0; i < numProjects; i += CHUNK) {
|
||||
await Project.find({}).skip(i).limit(CHUNK).exec()
|
||||
.then((err, projects) => {
|
||||
projects.forEach((project, projectIndex) => {
|
||||
console.log(project.name);
|
||||
project.files.forEach((file, fileIndex) => {
|
||||
if (file.url && file.url.includes('p5.js-webeditor')) {
|
||||
file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET);
|
||||
}
|
||||
project.save((err, savedProject) => {
|
||||
console.log(`updated file ${file.url}`);
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Project.find({}, (err, projects) => {
|
||||
// projects.forEach((project, projectIndex) => {
|
||||
|
|
Loading…
Reference in a new issue