From 36a95c003aa9d66ea29befbcd9ac5c10e6d76938 Mon Sep 17 00:00:00 2001 From: otofune Date: Tue, 7 Nov 2017 22:39:17 +0900 Subject: [PATCH] fix --- tools/migration/use-gridfs.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/migration/use-gridfs.js b/tools/migration/use-gridfs.js index 228943f49f..bb7070f553 100644 --- a/tools/migration/use-gridfs.js +++ b/tools/migration/use-gridfs.js @@ -48,16 +48,24 @@ const migrateToGridFS = async (doc) => { async function main() { const count = await DriveFile.count({}); + console.log(`there are ${count} files.`) + const dop = Number.parseInt(process.argv[2]) || 5 + const idop = ((count - (count % dop)) / dop) + 1 return zip( 1, async (time) => { - const doc = await DriveFile.find({}, { limit: dop, skip: time * dop }) + console.log(`${time} / ${idop}`) + const doc = await db.get('drive_files').find({}, { limit: dop, skip: time * dop }) return Promise.all(doc.map(migrateToGridFS)) }, - ((count - (count % dop)) / dop) + 1 - ) + idop + ).then(a => { + const rv = [] + a.forEach(e => rv.push(...e)) + return rv + }) } main().then(console.dir).catch(console.error)