Easysoft ODBC-MongoDB Driver User's Guide - Technical Reference

Technical Reference for the Easysoft ODBC-MongoDB Driver

This section contains extra information relating to the deployment of the Easysoft ODBC-MongoDB Driver.

Appendix Guide

ODBC Conformance

The Easysoft ODBC-MongoDB Driver complies with the ODBC 3.51 specification.

Unicode

The Easysoft ODBC-MongoDB Driver is a Unicode ODBC driver and supports the Unicode ODBC APIs and data types.

The Easysoft ODBC-MongoDB Driver does not support Unicode strings in SQL statements.

To work with Unicode data, use parameterised SQL and bind the statement parameters as Unicode data types. If your application calls SQLGetData, request that the data be returned as a Unicode data type.

Features

SQL Engine

To enable client applications to use SQL statements against MongoDB, the Easysoft ODBC-MongoDB Driver uses the SQL Engine feature to translate standard SQL-92 queries into equivalent MongoDB API calls.

Authentication

The Easysoft ODBC-MongoDB Driver enforces MongoDB's built in authentication. If your MongoDB instance uses authentication, you need to supply the user name and password for a user who has the necessary privileges, when configuring your data source. To retrieve MongoDB data, the user needs to have the read database role. To update MongoDB data, the user needs to have the readWrite database role.

Catalog Support

The Easysoft ODBC-MongoDB Driver uses the name of the MongoDB database as the catalog to make it easy for the driver to work with the various ODBC applications that expect a catalog name.

Embedded Documents

The Easysoft ODBC-MongoDB Driver flattens an embedded document into a relational structure. The driver also returns the original (i.e non flattened) embedded document in a separate column, which you have the option of hiding in the Schema Editor Tool.

To illustrate how the Easysoft ODBC-MongoDB Driver handles embedded documents, here is an example. Given this document to retrieve:

{

_id: "joe",

name: "Joe Bookreader",

address: {

street: "123 Fake Street",

city: "Faketon",

state: "MA",

zip: "12345"

}

}

The Easysoft ODBC-MongoDB Driver returns:

"_id", "name", "address", "address_street", "address_city", "address_state", "address_zip"

"joe", "Joe Bookreader", "{ "street" : "123 Fake Street", "city" : "Faketon", "state" : "MA", "zip" : "12345" }", "123 Fake Street", "Faketon", "MA", "12345"

The embedded document containing the address is returned as the address column value. The fields in the embedded document are flattened into the columns address_street, address_city, address_state and address_zip.

Arrays

The Easysoft ODBC-MongoDB Driver flattens an array into a relational structure. The column names include the index of the item in the array that the column represents, starting with an index of 0. The driver also returns the original (i.e non flattened) array in a separate column, which you have the option of hiding in the Schema Editor Tool.

To illustrate how the Easysoft ODBC-MongoDB Driver handles arrays, here is an example. Given this document to retrieve:

db.inventory.insert(

{

item: "ABC1",

details: {

model: "14Q3",

manufacturer: "XYZ Company"

},

stock: [ { size: "S", qty: 25 }, { size: "M", qty: 50 } ],

category: "clothing"

}

)

The Easysoft ODBC-MongoDB Driver returns:

"_id", "item", "details", "details_model", "details_manufacturer", "stock", "stock_0_size", "stock_0_qty", "stock_1_size", "stock_1_qty", "category"

"542ac8247bbc8c71916b3eb9", "ABC1", "{ "model" : "14Q3", "manufacturer" : "XYZ Company" }", "14Q3", "XYZ Company", "[ { "0" : { "size" : "S", "qty" : 25.000000 }, "1" : { "size" : "M", "qty" : 50.000000 } } ]", "S", 25.000000, "M", 50.000000, "clothing"

The array containing the stock is returned as the stock column value. The fields in the array are flattened into the columns stock_0_size, stock_0_qty, stock_1_size and stock_1_qty.

This behaviour can be changed using the Easysoft MongoDB Schema Editor to split a top-level array into virtual tables. For more information, see Creating a Schema for your MongoDB Data.

Tracing

The ODBC calls an application makes can be traced:

Within the driver manager by an application

An application can turn tracing on in the Driver Manager by using the ODBC API SQLSetConnectAttr (...,SQL_ATTR_TRACE,...).

The trace file name may also be specified with the SQLSetConnectAttr attribute SQL_ATTR_TRACEFILE.

From within the driver manager on Unix

For the unixODBC Driver Manager, add two attributes to the [ODBC] section (create one if none exists) in odbcinst.ini.

Trace = Yes

TraceFile =logfile

For example:

[ODBC]

Trace = Yes

TraceFile = /tmp/unixodbc.log

Ensure that the user who is running the application to be traced has write permission to the log file (and to the directory containing it), or no tracing information will be produced.

From within the driver manager on Windows

Click on Tracing, ensure the specified filename is valid and click Start Tracing Now.


64-bit Windows

There is both a 64-bit and 32-bit version of the ODBC Data Source Administrator. The 64-bit version enables you to trace the ODBC API calls that are made by a 64-bit application. The 32-bit version enables you to trace the ODBC API calls that are made by a 32-bit application.

The 64-bit version is located in Control Panel (see the previous step). To run the 32-bit version on Windows 7 and earlier, in the Windows Run dialog box, type:

%windir%\syswow64\odbcad32.exe

On Windows 8 and Windows 2012, both the 32-bit and 64-bit ODBC Administrator are located in Control Panel under Administrative tools: ODBC Data Sources (32-bit) and ODBC Data Sources (64-bit).

If you are not sure which version to use, and do not get a log file after completing the steps in this article, try enabling tracing in the other version of ODBC Data Source Administrator.


From within the Easysoft ODBC-MongoDB Driver on Unix

Driver manager trace files show all the ODBC calls applications make, their arguments and return values. Easysoft ODBC-MongoDB Driver driver tracing is specific to the Easysoft driver and is of most use when making a support call.

To enable Easysoft ODBC-MongoDB Driver logging, add a LOGFILE and a LOGGING attribute to the relevant DSN section of the odbc.ini file.

For example:

[MONGODB_SAMPLE]

.

.

.

LOGFILE = /tmp/mongodb-driver.log

LOGGING = Yes

The LOGFILE value is the path and file name of the log file. The value shown in the example specifies a log file named /tmp/mongodb.log. The LOGGING value specifies the actions to log. The value shown in the example specifies that all actions should be logged.

Ensure that the user who is running the application to be traced has write permission to the log file (and to the directory containing it).

From within the Easysoft ODBC-MongoDB Driver on Windows

To enable logging:

1.  Open the relevant Easysoft ODBC-MongoDB Driver data source in ODBC Data Source Administrator.

2.  Select Driver Logging.

3.  Type the file name and path of the file you want the driver to write log information to in the space provided.