Skip to content

Commit

Permalink
source-mongodb-v2: remove dependency on airbyte-commons source (airby…
Browse files Browse the repository at this point in the history
  • Loading branch information
postamar authored and jatinyadav-cc committed Feb 26, 2024
1 parent 6e7b9ba commit 0e9e172
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ dependencies {
integrationTestJavaImplementation libs.apache.commons.lang
integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-mongodb-v2')

dataGeneratorImplementation project(':airbyte-cdk:java:airbyte-cdk:airbyte-commons')
dataGeneratorImplementation platform(libs.fasterxml)
dataGeneratorImplementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'

dataGeneratorImplementation project(':airbyte-integrations:connectors:source-mongodb-v2')
dataGeneratorImplementation libs.mongo.driver.sync
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.airbyte.integrations.source.mongodb

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.github.javafaker.Faker
import io.airbyte.commons.json.Jsons
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.cli.ArgParser
import kotlinx.cli.ArgType
Expand Down Expand Up @@ -31,7 +34,7 @@ object MongoDbInsertClient {
println("Enter password: ")
val password = readln()

var config = mapOf(MongoConstants.DATABASE_CONFIG_CONFIGURATION_KEY to
val config = mapOf(MongoConstants.DATABASE_CONFIG_CONFIGURATION_KEY to
mapOf(
MongoConstants.DATABASE_CONFIGURATION_KEY to databaseName,
MongoConstants.CONNECTION_STRING_CONFIGURATION_KEY to connectionString,
Expand All @@ -42,7 +45,12 @@ object MongoDbInsertClient {

val faker = Faker();

MongoConnectionUtils.createMongoClient(MongoDbSourceConfig(Jsons.deserialize(Jsons.serialize(config)))).use { mongoClient ->
val objectMapper = ObjectMapper().registerModule(JavaTimeModule())
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true)
val roundTrippedConfig = objectMapper.readTree(objectMapper.writeValueAsBytes(config))

MongoConnectionUtils.createMongoClient(MongoDbSourceConfig(roundTrippedConfig)).use { mongoClient ->
val documents = mutableListOf<Document>()
val batches = if (numberOfDocuments > BATCH_SIZE) numberOfDocuments / BATCH_SIZE else 1;
val batchSize = if (numberOfDocuments > BATCH_SIZE) BATCH_SIZE else numberOfDocuments;
Expand Down

0 comments on commit 0e9e172

Please sign in to comment.