MongoFetcher
It exposes a function mongoForeach()
which, given a collection and a query, will perform an async task for every document matching the query.
For example, let's assume we want to remove all our archives in a S3 bucket, which are referenced in mongo.
Our File
collection contains documents which look like this :
{
documentType: string,
name: string,
... [other fields]
}
We could use our mongoForeach
to upload them with a high throughput :
const { mongoForeach } = require('@payfit/mongo-fetcher')
const db = require('./db')
const s3service = require('./s3service')
await mongoForeach(
db.collection('File'),
{ documentType: 'archive' },
async file => {
try {
await s3service.deleteFile(file.name)
await db.collection('File').removeOne({ _id: file._id })
} catch (err) {
}
},
{
batchSize: 150,
concurrency: 20,
}
)