diff --git a/lib/richlist/storage/mongo.js b/lib/richlist/storage/mongo.js index c944d36..0999979 100644 --- a/lib/richlist/storage/mongo.js +++ b/lib/richlist/storage/mongo.js @@ -191,13 +191,22 @@ class MongoStorage { } } + const insertManyCollection = (collection, data) => { + if(data.length === 0) { + return Promise.resolve() + } + // insertMany fails when data is empty array + // (node:1) UnhandledPromiseRejectionWarning: MongoError: Invalid Operation, no operations specified + return collection.insertMany(data) + } + // insert documents - return this.transactions.insertMany(txs.map(tx => ({ + return insertManyCollection(this.transactions, txs.map(tx => ({ hash: tx.hash, locktime: tx.locktime, version: tx.version }))).then(() => { - return this.outputs.insertMany(outputs); + return insertManyCollection(this.outputs, outputs); }).then(() => this.blocks.insertOne({ hash: block.hash, height: block.height,