dev: update dev script for auto-download
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const { MongoClient, ObjectId } = require('mongodb');
|
||||
const fs = require('fs');
|
||||
const { createReadStream } = require('fs');
|
||||
const { createInterface } = require('readline');
|
||||
const path = require('path');
|
||||
import { MongoClient, ObjectId } from 'mongodb';
|
||||
import fs from 'fs';
|
||||
import { createReadStream } from 'fs';
|
||||
import { createInterface } from 'readline';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
/**
|
||||
* Stream-based import of large JSON files
|
||||
@@ -121,7 +125,7 @@ async function importLargeJsonFile(filePath, collectionName, batchSize = 1000) {
|
||||
}
|
||||
|
||||
// Run the import if called directly
|
||||
if (require.main === module) {
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 2) {
|
||||
console.log('Usage: node process-matches.js <file-path> <collection-name> [batch-size]');
|
||||
@@ -141,4 +145,4 @@ if (require.main === module) {
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { importLargeJsonFile };
|
||||
export { importLargeJsonFile };
|
||||
|
||||
Reference in New Issue
Block a user