-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Source MongoDB Internal POC: Generate Test Data #29049
Merged
octavia-approvington
merged 7 commits into
master
from
jonathan/generate-mongo-test-data
Aug 3, 2023
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
64b3770
Add script to generate test data
jdpgrailsdev 327affe
Merge branch 'master' into jonathan/generate-mongo-test-data
jdpgrailsdev cf274ce
Merge branch 'master' into jonathan/generate-mongo-test-data
jdpgrailsdev 750c178
Fix prose
jdpgrailsdev d30665a
Update credentials example
jdpgrailsdev 6583bd0
Merge branch 'master' into jonathan/generate-mongo-test-data
jdpgrailsdev 4a2ddda
PR feedback
jdpgrailsdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ntegrations/connectors/source-mongodb-internal-poc/src/test/kotlin/MongoDbInsertClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.airbyte.integrations.source.mongodb.internal | ||
|
||
import io.airbyte.commons.json.Jsons | ||
import kotlinx.cli.ArgParser | ||
import kotlinx.cli.ArgType | ||
import kotlinx.cli.default | ||
import kotlinx.cli.required | ||
import org.bson.BsonTimestamp | ||
import org.bson.Document | ||
import java.lang.System.currentTimeMillis | ||
|
||
object MongoDbInsertClient { | ||
|
||
@JvmStatic | ||
fun main(args: Array<String>) { | ||
val parser = ArgParser("MongoDb Insert Client") | ||
val connectionString by parser.option(ArgType.String, fullName = "connection-string", shortName = "cs", description = "MongoDb Connection String").required() | ||
val databaseName by parser.option(ArgType.String, fullName = "database-name", shortName = "d", description = "Database Name").required() | ||
val collectionName by parser.option(ArgType.String, fullName = "collection-name", shortName = "cn", description = "Collection Name").required() | ||
val replicaSet by parser.option(ArgType.String, fullName = "replica-set", shortName = "r", description = "Replica Set").required() | ||
val username by parser.option(ArgType.String, fullName = "username", shortName = "u", description = "Username").required() | ||
val numberOfDocuments by parser.option(ArgType.Int, fullName = "number", shortName = "n", description = "Number of documents to generate").default(10000) | ||
|
||
parser.parse(args) | ||
|
||
println("Enter password: ") | ||
var password = readln() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
|
||
var config = mapOf(MongoConstants.DATABASE_CONFIGURATION_KEY to databaseName, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
MongoConstants.CONNECTION_STRING_CONFIGURATION_KEY to connectionString, | ||
MongoConstants.AUTH_SOURCE_CONFIGURATION_KEY to "admin", | ||
MongoConstants.REPLICA_SET_CONFIGURATION_KEY to replicaSet, | ||
MongoConstants.USER_CONFIGURATION_KEY to username, | ||
MongoConstants.PASSWORD_CONFIGURATION_KEY to password) | ||
|
||
MongoConnectionUtils.createMongoClient(Jsons.deserialize(Jsons.serialize(config))).use { mongoClient -> | ||
var documents = mutableListOf<Document>() | ||
for (i in 0..numberOfDocuments) { | ||
documents += Document().append("name", "Document $i") | ||
.append("description", "This is document #$i") | ||
.append("doubleField", i.toDouble()) | ||
.append("intField", i) | ||
.append("objectField", mapOf("key" to "value")) | ||
.append("timestamp", BsonTimestamp(currentTimeMillis())) | ||
} | ||
|
||
mongoClient.getDatabase(databaseName).getCollection(collectionName).insertMany(documents) | ||
} | ||
|
||
println("Inserted $numberOfDocuments document(s) to $databaseName.$collectionName") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL