Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00e49d6

Browse files
committed
change move bucket name to use async
1 parent b2ee44a commit 00e49d6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

server/migrations/moveBucket.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'path';
44
import mongoose from 'mongoose';
55
import User from '../models/user';
66
import Project from '../models/project';
7+
import async from 'async';
78
require('dotenv').config({path: path.resolve('.env')});
89
mongoose.connect('mongodb://localhost:27017/p5js-web-editor');
910
mongoose.connection.on('error', () => {
@@ -30,15 +31,23 @@ Project.count({})
3031
console.log(numProjects);
3132
for (let i = 0; i < numProjects; i += CHUNK) {
3233
let projects = await Project.find({}).skip(i).limit(CHUNK).exec();
33-
projects.forEach((project, projectIndex) => {
34+
async.eachSeries(projects, (project, cb) => {
3435
console.log(project.name);
35-
project.files.forEach(async (file, fileIndex) => {
36+
async.eachSeries(project.files, (file, fileCb) => {
3637
if (file.url && file.url.includes('p5.js-webeditor')) {
3738
file.url = file.url.replace('p5.js-webeditor', process.env.S3_BUCKET);
38-
let savedProject = await project.save();
39-
console.log(`updated file ${file.url}`);
40-
process.exit(0);
39+
project.save((err, newProject) => {
40+
console.log(`updated file ${file.url}`);
41+
process.exit(0);
42+
fileCb();
43+
});
44+
} else {
45+
fileCb();
4146
}
47+
}, () => {
48+
cb();
49+
}, () => {
50+
console.log('at ' + i);
4251
});
4352
});
4453
}

0 commit comments

Comments
 (0)