-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Source MongoDB Internal POC: Generate Test Data (#29049)
* Add script to generate test data * Fix prose * Update credentials example * PR feedback
- Loading branch information
1 parent
0fc2a35
commit 2ac04d1
Showing
3 changed files
with
88 additions
and
5 deletions.
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: ") | ||
val password = readln() | ||
|
||
var config = mapOf(MongoConstants.DATABASE_CONFIGURATION_KEY to databaseName, | ||
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 -> | ||
val 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") | ||
} | ||
} |