Implementation
This handler is implemented by extending the MongoDBHandler.
The required arguments to establish a connection are as follows:
usernameis the database user.passwordis the database password.hostis the host IP address or URL.portis the port used to make TCP/IP connection.databaseis the database name.
There are several optional arguments (refer https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html) that can be used as well and can be passed as kwargs:
tlsindicates whether tls is enabled (True) or disabled (False).serverSelectionTimeoutMSControls how long (in milliseconds) the driver will wait to find an available.directConnectionifTrue, forces this client to connect directly to the specified DocumentDB host as a standalone. IfFalse, the client connects to the entire replica set of which the given DocumentDB host(s) is a part.tlsAllowInvalidHostnamesIfTrue, disables TLS hostname verification.Falseimplies tls=True.tlsAllowInvalidCertificatesIfTrue, continues the TLS handshake regardless of the outcome of the certificate verification process.retryWritesWhether supported write operations executed within this MongoClient will be retried once after a network error.tlsCAFileA file containing a single or a bundle of “certification authority” certificates, which are used to validate certificates passed from the other end of the connection.
Usage
In order to make use of this handler and connect to the DocuementDB database in MindsDB, the following syntax can be used:
db.databases.insertOne({
name: "example_documentdb",
engine: "documentdb",
connection_args: {
"username": "username",
"password": "password",
"host": "127.0.0.1",
"port": "27017",
"database": "sample_database",
"kwargs": {
"directConnection": true,
"serverSelectionTimeoutMS": 2000,
"tls": true,
"tlsAllowInvalidHostnames": true,
"tlsAllowInvalidCertificates": true,
"retryWrites": false,
"tlsCAFile": "/home/global-bundle.pem"
}
}
});
You can use this established connection to query your table as follows.
use example_documentdb;
show collections;
db.sample_collection.find({});