@@ -73,22 +73,49 @@ use(${JSON.stringify(options.databaseName)});
7373
7474// Document generation function
7575function generateDocument() {
76- return ${ documentCode } ;
76+ return ${ documentCode } ;
7777}
7878
79- // Generate and insert documents
80- const documents = [];
81- for (let i = 0; i < ${ options . documentCount } ; i++) {
82- documents.push(generateDocument());
79+ const BATCH_SIZE = 1000; // Number of documents to insert per batch
80+ const TOTAL_DOCUMENTS = ${ options . documentCount } ;
81+ const numBatches = Math.ceil(TOTAL_DOCUMENTS / BATCH_SIZE);
82+
83+ console.log(\`Starting mock data generation for ${ options . databaseName . replace (
84+ / [ \\ ` $ ] / g,
85+ '\\$&'
86+ ) } .${ options . collectionName . replace ( / [ \\ ` $ ] / g, '\\$&' ) } \`);
87+ console.log(\`Total documents to generate: \${TOTAL_DOCUMENTS} documents\`);
88+ console.log(\`Batch size: \${BATCH_SIZE} documents per batch\`);
89+
90+ const startTime = new Date();
91+
92+ for (let batchStart = 0; batchStart < TOTAL_DOCUMENTS; batchStart += BATCH_SIZE) {
93+ const batchEnd = Math.min(batchStart + BATCH_SIZE, TOTAL_DOCUMENTS);
94+ const batchSize = batchEnd - batchStart;
95+
96+ console.log(\`Generating batch \${Math.floor(batchStart / BATCH_SIZE) + 1} of \${numBatches} (\${batchSize} documents)...\`);
97+
98+ // Generate documents for this batch
99+ const batchDocuments = [];
100+ for (let i = 0; i < batchSize; i++) {
101+ batchDocuments.push(generateDocument());
102+ }
103+
104+ // Insert the batch
105+ db.getCollection(${ JSON . stringify (
106+ options . collectionName
107+ ) } ).insertMany(batchDocuments);
108+
109+ console.log(\`Batch inserted successfully.\`);
83110}
84111
85- // Insert documents into collection
86- db.getCollection(${ JSON . stringify (
87- options . collectionName
88- ) } ).insertMany(documents);
112+ const endTime = new Date();
113+ const duration = ((endTime - startTime) / 1000).toFixed(2);
89114
90- console.log(\`Successfully inserted \${documents.length} documents into ${ options . databaseName . replace (
91- / [ \\ ` $ ] / g, // Escape backslashes, backticks and dollar signs
115+ console.log(\`\\n=== Mock Data Generation Complete ===\`);
116+ console.log(\`Total time: \${duration} seconds\`);
117+ console.log(\`Collection: ${ options . databaseName . replace (
118+ / [ \\ ` $ ] / g,
92119 '\\$&'
93120 ) } .${ options . collectionName . replace ( / [ \\ ` $ ] / g, '\\$&' ) } \`);`;
94121
0 commit comments