Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,49 @@ use(${JSON.stringify(options.databaseName)});

// Document generation function
function generateDocument() {
return ${documentCode};
return ${documentCode};
}

// Generate and insert documents
const documents = [];
for (let i = 0; i < ${options.documentCount}; i++) {
documents.push(generateDocument());
const BATCH_SIZE = 1000; // Number of documents to insert per batch
const TOTAL_DOCUMENTS = ${options.documentCount};
const numBatches = Math.ceil(TOTAL_DOCUMENTS / BATCH_SIZE);

console.log(\`Starting mock data generation for ${options.databaseName.replace(
/[\\`$]/g,
'\\$&'
)}.${options.collectionName.replace(/[\\`$]/g, '\\$&')}\`);
console.log(\`Total documents to generate: \${TOTAL_DOCUMENTS} documents\`);
console.log(\`Batch size: \${BATCH_SIZE} documents per batch\`);

const startTime = new Date();

for (let batchStart = 0; batchStart < TOTAL_DOCUMENTS; batchStart += BATCH_SIZE) {
const batchEnd = Math.min(batchStart + BATCH_SIZE, TOTAL_DOCUMENTS);
const batchSize = batchEnd - batchStart;

console.log(\`Generating batch \${Math.floor(batchStart / BATCH_SIZE) + 1} of \${numBatches} (\${batchSize} documents)...\`);

// Generate documents for this batch
const batchDocuments = [];
for (let i = 0; i < batchSize; i++) {
batchDocuments.push(generateDocument());
}

// Insert the batch
db.getCollection(${JSON.stringify(
options.collectionName
)}).insertMany(batchDocuments);

console.log(\`Batch inserted successfully.\`);
}

// Insert documents into collection
db.getCollection(${JSON.stringify(
options.collectionName
)}).insertMany(documents);
const endTime = new Date();
const duration = ((endTime - startTime) / 1000).toFixed(2);

console.log(\`Successfully inserted \${documents.length} documents into ${options.databaseName.replace(
/[\\`$]/g, // Escape backslashes, backticks and dollar signs
console.log(\`\\n=== Mock Data Generation Complete ===\`);
console.log(\`Total time: \${duration} seconds\`);
console.log(\`Collection: ${options.databaseName.replace(
/[\\`$]/g,
'\\$&'
)}.${options.collectionName.replace(/[\\`$]/g, '\\$&')}\`);`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const ScriptScreen = ({
onScriptCopy({ step: DataGenerationStep.INSTALL_FAKERJS })
}
>
npm install @faker-js/faker
npm install @faker-js/faker@9
</Copyable>
</li>
</ul>
Expand All @@ -190,8 +190,8 @@ const ScriptScreen = ({
1. Create a .js file with the following script
</Body>
<Body className={sectionInstructionStyles}>
In the directory that you created, create a file named
mockdatascript.js (or any name you&apos;d like).
In the directory that you created, create a file named{' '}
<strong>mockdatascript.js</strong> (or any name you&apos;d like).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bolding this

</Body>
<Code
copyButtonAppearance={scriptResult.success ? 'hover' : 'persist'}
Expand Down
Loading