Trying to fetch documents from Mongodb using jdbc input plugin in logstash but getting this error messages

Hi All.There are documents in my Mongodb which I am trying to fetch out using logstash input jdbc plugin.I am using mongodb version 4.2.15 and logstash version is 7.10.1.When I run the logstash configuration pipeline I get this following error messages.

This is my logstash configuration pipeline:-

input {

    jdbc {

        jdbc_driver_library => "/usr/share/java/mongojdbc3.1.jar"

        jdbc_driver_class => "Java::com.dbschema.MongoJdbcDriver"

        jdbc_connection_string => "jdbc:mongodb://logstash:password@localhost:27017/company?authSource=admin"

        jdbc_user => "logstash"

        jdbc_password => "password"

        # schedule => "*/30 * * * * *"

         statement => "db.employees.find({},{'_id': false});"

    }

}

output {

    stdout {

        codec => rubydebug

    }

}

I get this following error messages:-

[INFO ] 2021-11-14 09:57:52.062 [Api Webserver] agent - Successfully started Logstash API endpoint {:port=>9600}
java.nio.file.NoSuchFileException: /root/.DbSchema/logs/MongoDbJdbcDriver.log.lck
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
        at java.base/sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:182)
        at java.base/java.nio.channels.FileChannel.open(FileChannel.java:292)
        at java.base/java.nio.channels.FileChannel.open(FileChannel.java:345)
        at java.logging/java.util.logging.FileHandler.openFiles(FileHandler.java:511)
        at java.logging/java.util.logging.FileHandler.<init>(FileHandler.java:307)
        at com.dbschema.MongoJdbcDriver.<clinit>(MongoJdbcDriver.java:37)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at org.jruby.javasupport.JavaSupportImpl.loadJavaClass(JavaSupportImpl.java:157)
        at org.jruby.javasupport.Java.getProxyClassOrNull(Java.java:961)
        at org.jruby.javasupport.Java.getProxyClassOrNull(Java.java:948)
        at org.jruby.javasupport.Java.getProxyOrPackageUnderPackage(Java.java:905)
        at org.jruby.javasupport.JavaPackage.method_missing(JavaPackage.java:252)
        at org.jruby.javasupport.JavaPackage$INVOKER$i$method_missing.call(JavaPackage$INVOKER$i$method_missing.gen)
        at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:833)
        at org.jruby.runtime.Helpers$MethodMissingMethod.call(Helpers.java:408)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:196)
        at org.jruby.runtime.callsite.CachingCallSite.callMethodMissing(CachingCallSite.java:439)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:351)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:143)
        at org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:345)
        at org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:72)
        at org.jruby.ir.interpreter.Interpreter.INTERPRET_EVAL(Interpreter.java:106)
        at org.jruby.ir.interpreter.Interpreter.evalCommon(Interpreter.java:158)
        at org.jruby.ir.interpreter.Interpreter.evalWithBinding(Interpreter.java:182)
        at org.jruby.RubyKernel.evalCommon(RubyKernel.java:1086)
        at org.jruby.RubyKernel.eval(RubyKernel.java:1048)
        at org.jruby.RubyKernel$INVOKER$s$0$3$eval.call(RubyKernel$INVOKER$s$0$3$eval.gen)
        at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:207)
        at usr.share.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.sequel_minus_5_dot_38_dot_0.lib.sequel.adapters.jdbc.RUBY$method$load_driver$0(/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/sequel-5.38.0/lib/sequel/adapters/jdbc.rb:55)
        at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:80)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:70)
        at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:207)
        at usr.share.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.logstash_minus_integration_minus_jdbc_minus_5_dot_0_dot_6.lib.logstash.plugin_mixins.jdbc.common.RUBY$method$load_driver$0(/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.6/lib/logstash/plugin_mixins/jdbc/common.rb:27)
        at usr.share.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.logstash_minus_integration_minus_jdbc_minus_5_dot_0_dot_6.lib.logstash.plugin_mixins.jdbc.common.RUBY$method$load_driver$0$__VARARGS__(/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.6/lib/logstash/plugin_mixins/jdbc/common.rb)
        at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:80)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:70)
        at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:207)
        at usr.share.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.logstash_minus_integration_minus_jdbc_minus_5_dot_0_dot_6.lib.logstash.inputs.jdbc.RUBY$method$run$0(/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.6/lib/logstash/inputs/jdbc.rb:275)
        at usr.share.logstash.vendor.bundle.jruby.$2_dot_5_dot_0.gems.logstash_minus_integration_minus_jdbc_minus_5_dot_0_dot_6.lib.logstash.inputs.jdbc.RUBY$method$run$0$__VARARGS__(/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.6/lib/logstash/inputs/jdbc.rb)
        at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:80)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:70)
        at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:207)
        at usr.share.logstash.logstash_minus_core.lib.logstash.java_pipeline.RUBY$method$inputworker$0(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:405)
        at usr.share.logstash.logstash_minus_core.lib.logstash.java_pipeline.RUBY$method$inputworker$0$__VARARGS__(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb)
        at org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:80)
        at org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:70)
        at org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:207)
        at usr.share.logstash.logstash_minus_core.lib.logstash.java_pipeline.RUBY$block$start_input$1(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:396)
        at org.jruby.runtime.CompiledIRBlockBody.callDirect(CompiledIRBlockBody.java:138)
        at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:58)
        at org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:52)
        at org.jruby.runtime.Block.call(Block.java:139)
        at org.jruby.RubyProc.call(RubyProc.java:318)
        at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:105)
        at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR] 2021-11-14 09:57:52.713 [[main]<jdbc] jdbc - Unable to connect to database. Tried 1 times {:error_message=>"Java::JavaLang::NoClassDefFoundError: com/mongodb/event/ServerMonitorListener"}
[ERROR] 2021-11-14 09:57:52.728 [[main]<jdbc] javapipeline - A plugin had an unrecoverable error. Will restart this plugin.
  Pipeline_id:main
  Plugin: <LogStash::Inputs::Jdbc jdbc_user=>"logstash", jdbc_password=><password>, statement=>"db.employees.find({},{'_id': false});", jdbc_driver_library=>"/usr/share/java/mongojdbc3.1.jar", jdbc_connection_string=>"jdbc:mongodb://logstash:python@localhost:27017/company?authSource=admin", id=>"85ba9a34f506be54082a17642717f4f2abf251383014d62615a1450a5db846e0", jdbc_driver_class=>"Java::com.dbschema.MongoJdbcDriver", enable_metric=>true, codec=><LogStash::Codecs::Plain id=>"plain_09f2a382-2fe4-4edd-a242-98dcd905085c", enable_metric=>true, charset=>"UTF-8">, jdbc_paging_enabled=>false, jdbc_page_size=>100000, jdbc_validate_connection=>false, jdbc_validation_timeout=>3600, jdbc_pool_timeout=>5, sql_log_level=>"info", connection_retry_attempts=>1, connection_retry_attempts_wait_time=>0.5, plugin_timezone=>"utc", last_run_metadata_path=>"/root/.logstash_jdbc_last_run", use_column_value=>false, tracking_column_type=>"numeric", clean_run=>false, record_last_run=>true, lowercase_column_names=>true, use_prepared_statements=>false>
  Error: Java::JavaLang::NoClassDefFoundError: com/mongodb/event/ServerMonitorListener
  Exception: Sequel::DatabaseConnectionError
  Stack: com.dbschema.MongoJdbcDriver.connect(com/dbschema/MongoJdbcDriver.java:69)
jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Help needed asap

See How to Ingest data from MongoDB database into ElasticSearch using Logstash - #5 by jskishor

Hi @Alex_Marquardt.Thanks for your reply.I will refer this link which you have provided

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.