OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Error Connecting MongoDB with JDBC: CommandNotFound for 'sqlGetResultSchema'

  • Thread starter Thread starter Syed Mohsin Karim
  • Start date Start date
S

Syed Mohsin Karim

Guest
I am using MongoDB docker image mongo:4.4 and is working fine with DBeaverEE (MongoDB) and Robo 3T.

I am trying to connect with MongoDB with JDBC using jaydebeapi.connect(...), also I have put all related jars (such as mongodb-jdbc-2.1.4.jar and mongodb-driver-sync-4.7.1.jar).

My Code: I added {username}:{password} in a string as it gave me a null username error without it.

Code:
driver_name = "com.mongodb.jdbc.MongoDriver"
jdbc_url = f"jdbc:mongodb://{username}:{password}@{host}:{port}/{database}?authSource=admin&authMechanism=SCRAM-SHA-1"

jar_folder = "jars_test"

jar_folder = os.path.abspath(jar_folder)

jar_files = [os.path.join(jar_folder, file) for file in os.listdir(jar_folder) if file.endswith(".jar")]

# Start the JVM with the JDBC driver JAR files
if not jpype.isJVMStarted():
    # Start the JVM with the JDBC driver JAR files
    jpype.startJVM(
        jpype.getDefaultJVMPath(),
        "-Djava.class.path={}".format(os.pathsep.join(jar_files))
    )

try:
    # Connect to MongoDB using JayDeBeApi
    conn = jaydebeapi.connect(
        driver_name,
        jdbc_url,
        [username, password],
    )
    print("Connection successful and query executed.")
    conn.close()

except Exception as e:
    print(f"Error: {e}")
    raise e

And I got this error:

Code:
com.mongodb.MongoCommandException: com.mongodb.MongoCommandException: Command failed with error 59 (CommandNotFound): 'no such command: 'sqlGetResultSchema'' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "no such command: 'sqlGetResultSchema'", "code": 59, "codeName": "CommandNotFound"}

I didn't find any solution for it and the assumption is that Mongo DB doesn't support this Command.

Any Suggestions and possible solutions for MongoDB connectivity using JDBC?
<p>I am using MongoDB docker image <code>mongo:4.4</code> and is working fine with DBeaverEE (MongoDB) and Robo 3T.</p>
<p>I am trying to connect with MongoDB with JDBC using <code>jaydebeapi.connect(...)</code>, also I have put all related jars (such as <code>mongodb-jdbc-2.1.4.jar</code> and <code>mongodb-driver-sync-4.7.1.jar</code>).</p>
<p>My Code:
I added <code>{username}:{password}</code> in a string as it gave me a null username error without it.</p>
<pre><code>driver_name = "com.mongodb.jdbc.MongoDriver"
jdbc_url = f"jdbc:mongodb://{username}:{password}@{host}:{port}/{database}?authSource=admin&authMechanism=SCRAM-SHA-1"

jar_folder = "jars_test"

jar_folder = os.path.abspath(jar_folder)

jar_files = [os.path.join(jar_folder, file) for file in os.listdir(jar_folder) if file.endswith(".jar")]

# Start the JVM with the JDBC driver JAR files
if not jpype.isJVMStarted():
# Start the JVM with the JDBC driver JAR files
jpype.startJVM(
jpype.getDefaultJVMPath(),
"-Djava.class.path={}".format(os.pathsep.join(jar_files))
)

try:
# Connect to MongoDB using JayDeBeApi
conn = jaydebeapi.connect(
driver_name,
jdbc_url,
[username, password],
)
print("Connection successful and query executed.")
conn.close()

except Exception as e:
print(f"Error: {e}")
raise e
</code></pre>
<p>And I got this error:</p>
<pre><code>com.mongodb.MongoCommandException: com.mongodb.MongoCommandException: Command failed with error 59 (CommandNotFound): 'no such command: 'sqlGetResultSchema'' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "no such command: 'sqlGetResultSchema'", "code": 59, "codeName": "CommandNotFound"}
</code></pre>
<p>I didn't find any solution for it and the assumption is that Mongo DB doesn't support this Command.</p>
<p>Any Suggestions and possible solutions for MongoDB connectivity using JDBC?</p>
 

Latest posts

Top