About the Easysoft ODBC-MongoDB Driver
The Easysoft ODBC-MongoDB Driver provides real-time access to MongoDB data from any application that supports ODBC.
ODBC API and scalar functions
API functions
Use this table to find out what ODBC API functions the Easysoft ODBC-MongoDB Driver supports:
Function | Status |
---|---|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Not supported |
|
Not supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
|
Supported |
Scalar functions
The Easysoft ODBC-MongoDB Driver supports a number of scalar functions:
String functions
The Easysoft ODBC-MongoDB Driver supports these string functions:
-
ASCII(string_exp)
-
BIT_LENGTH(string_exp)
-
CHAR(code)
-
CHAR_LENGTH(string_exp)
-
CHARACTER_LENGTH
(string_exp)` -
CONCAT(string_exp1, string_exp2)
-
INSERT(string_exp1, start, length, string_exp2)
-
LCASE(string_exp)
-
LEFT(string_exp, count)
-
LENGTH(string_exp)
-
LOCATE(string_exp1, string_exp2[,start])
-
LTRIM(string_exp)
-
OCTET_LENGTH(string_exp)
-
POSITION(char_exp IN char_exp)
-
REPEAT(string_exp, count)
-
REPLACE(string_exp1, string_exp2, string_exp3)
-
RIGHT(string_exp, count)
-
RTRIM(string_exp)
-
SOUNDEX(string_exp)
-
SPACE(count)
-
UCASE(string_exp)
Numeric functions
The Easysoft ODBC-MongoDB Driver supports these numeric functions:
-
ABS(numeric_exp)
-
ACOS(float_exp)
-
ASIN(float_exp)
-
ATAN(float_exp)
-
CEILING(numeric_exp)
-
COS(float_exp)
-
COT(float_exp)
-
DEGREES(numeric_exp)
-
EXP(float_exp)
-
FLOOR(numeric_exp)
-
LOG(float_exp)
-
LOG10(float_exp)
-
MOD(integer_exp1, integer_exp2)
-
PI()
-
POWER(numeric_exp, integer_exp)
-
RADIANS(numeric_exp)
-
RAND([integer_exp])
-
ROUND(numeric_exp, integer_exp)
-
SIGN(numeric_exp)
-
SIN(float_exp)
-
SQRT(float_exp)
-
TAN(float_exp)
-
TRUNCATE(numeric_exp, integer_exp)
Time, date, and interval functions
The Easysoft ODBC-MongoDB Driver supports these time, date, and interval functions:
-
CURRENT_DATE()
-
CURRENT_TIME[(time-precision)]
-
CURRENT_TIMESTAMP[(timestamp-precision)]
-
DAYNAME(date_exp)
-
DAYOFMONTH(date_exp)
-
DAYOFWEEK(date_exp)
-
DAYOFYEAR(date_exp)
-
EXTRACT(extract-field FROM extract-source)
-
HOUR(time_exp)
-
MINUTE(time_exp)
-
MONTH(date_exp)
-
MONTHNAME(date_exp)
-
QUARTER(date_exp)
-
SECOND(time_exp)
-
WEEK(date_exp)
-
YEAR(date_exp)
System functions
The Easysoft ODBC-MongoDB Driver supports these system functions:
-
DATABASE()
-
USER()
Conversion functions
The Easysoft ODBC-MongoDB Driver supports supports the SQL-92 CAST function for conversion between compatible data types.
Data type mapping
The Easysoft ODBC-MongoDB Driver maps MongoDB data types to ODBC data types in this way:
MongoDB data type | ODBC data type |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Further reading
Finding out more about data types on Windows
If you need more information about a data types, for example, the precision and scale, use Microsoft’s ODBC Test to do this.
-
Download the version of ODBC Test that matches your application’s architecture from:
-
Copy both files to a folder on the machine where Easysoft ODBC-MongoDB Driver is installed.
-
Double-click odbcte32.exe.
-
Select Con > Full Connect.
-
Choose your Easysoft ODBC-MongoDB Driver data source from the list.
-
Choose Catalog > SQLGetTypeInfo.
-
Either choose SQL_ALL_TYPES=0 (1.0) or a specific data type from the DataType list.
-
Choose Results > Get Data All.
Features
In this section:
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 (in other words, 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 {PRODUCT} 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 (in other words, 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 by using the Easysoft MongoDB Schema Editor to split a top-level array into virtual tables. For more information, refer to Creating a Schema for your MongoDB Data.
SQL support
The Easysoft ODBC-MongoDB Driver supports these SQL statements, clauses, and operators:
-
SELECT
-
SELECT DISTINCT
-
WHERE
-
ORDER BY
-
AND
-
OR
-
NOT
-
INSERT INTO
-
NULL
-
UPDATE
-
DELETE
-
FIRST
-
MIN
-
MAX
-
COUNT
-
SUM
-
AVG
-
LIKE
-
WILDCARDS
-
IN
-
BETWEEN
-
ALIASES
-
JOINS
-
UNION
-
GROUP BY
-
HAVING
-
EXISTS
-
CASE
Example queries
-
To fetch all records from a table, use the asterisk symbol (
*
) in your queries. For example:SELECT * FROM Customers
-
To only fetch records whose values are different, use
DISTINCT
. For example:-- Which different sales regions are there? SELECT DISTINCT Region AS Different_Regions FROM SalesOrders -- How many different sales regions are there? SELECT COUNT(DISTINCT Region) AS Different_Regions FROM SalesOrders
-
To filter records, use
WHERE
. For example:SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region = 'Eastern' SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region = 'Eastern' OR Region = 'Western' SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region = 'Eastern' AND EXTRACT(YEAR FROM OrderDate) = 2025
You can also supply a
WHERE
clause value as a parameter. For example, to do this in Python:cursor.execute("SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region = ?", ['Eastern'])
-
To fetch records that don’t match the
WHERE
clause pattern useNOT
. For example:SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE NOT Region = 'Eastern'
-
To sort the result set in either ascending or descending order, use
ORDER BY
. For example:SELECT * FROM SalesOrders ORDER BY OrderDate ASC SELECT * FROM Contacts ORDER BY ( CASE WHEN Surname IS NULL THEN Title ELSE Surname END );
-
To group a result set into summary rows, use
GROUP BY
. For example:SELECT COUNT(Id) As "Number", ProductID FROM SalesOrderItems GROUP BY ProductID SELECT COUNT(Id) As "Number", ProductID FROM SalesOrderItems GROUP BY ProductID HAVING COUNT(Id) > 100;
-
To do calculations based on result set vales, use the SQL aggregate functions
MIN()
,MAX()
,COUNT()
,SUM()
, andAVG()
. For example:SELECT Max(Quantity) FROM SalesOrderItems SELECT Sum(Quantity) FROM SalesOrderItems
-
To convert between compatible data types, use
CAST
. For example:SELECT CAST(Quantity AS Char(100))FROM SalesOrderItems
-
To fetch records that contain column values between a given range, use
BETWEEN
For example:SELECT ProductID FROM SalesOrderItems WHERE Quantity BETWEEN 10 AND 20
-
To combine the result set of two or more
SELECT
statements, useUNION
. For example:SELECT City FROM Contacts UNION SELECT City FROM Customers
-
To combine rows from two or more tables, use
JOIN
. For example:SELECT SalesOrders.ID, Customers.Surname, SalesOrders.OrderDate FROM SalesOrders INNER JOIN Customers ON SalesOrders.CustomerID=Customers.ID;
-
To fetch records that contain column values matching a search pattern, use
LIKE
. For example:SELECT Surname, GivenName FROM Customers WHERE CompanyName LIKE 'R%' SELECT Surname, GivenName FROM Customers WHERE CompanyName LIKE '_he'
-
To search for columns without a value (
NULL
) or with a value (nonNULL
), use eitherIS NULL
orIS NOT NULL
. For example:SELECT * FROM Customers WHERE CompanyName IS NULL
-
To specify multiple values in a
WHERE
clause, you can useIN
as an alternative toOR
. For example:SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region = 'Eastern' OR Region = 'Western' OR Region = 'Central'
can be replaced with:
SELECT OrderDate, SalesRepresentative FROM SalesOrders WHERE Region IN ('Eastern', 'Western', 'Central')
-
To set the maximum number of records to return, use
LIMIT
. For example:SELECT * FROM Customers LIMIT 10
-
To test for the existence of records in a subquery, use
EXISTS
. For example:SELECT Name FROM Products WHERE EXISTS ( SELECT * FROM SalesOrderItems WHERE Products.ID = SalesOrderItems.ProductID AND Quantity < 20 )
Example inserts, updates, and deletes
-
To insert a MongoDB record, use
INSERT INTO
. For example:INSERT INTO Customers ( Surname, GivenName, City, Phone, CompanyName ) VALUES ( 'Devlin', 'Michaels', 'Kingston', '2015558966', 'PowerGroup' )
-
Here’s a SQL Server linked server example:
EXEC ('INSERT INTO Customers (Surname, GivenName, City, Phone, CompanyName) VALUES (''Devlin'' , ''Michaels'' , ''Kingston'' , ''2015558966'' , ''PowerGroup'')')
-
Here’s an Oracle linked table example:
DECLARE num_rows integer; BEGIN num_rows:=DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@MongodbLink ('INSERT INTO Customers (Surname, GivenName, City, Phone, CompanyName) VALUES (''Devlin'', ''Michaels'', ''Kingston'', ''2015558966'', ''PowerGroup'')'); END; /
-
The Easysoft ODBC-MongoDB Driver also supports parameterized inserts. Here’s an example of doing this in Perl:
my $sth = $dbh->prepare(q/INSERT INTO Customers (Surname, GivenName, City, Phone, CompanyName) VALUES (?, ?, ?, ?, ?)/) or die "Can't prepare statement: $DBI::errstr"; $sth->execute('Devlin', 'Michaels', 'Kingston', '2015558966', 'PowerGroup');
-
To update a MongoDB record, use
UPDATE
. For example:UPDATE Customers SET Surname = 'Jones' WHERE Account_Id = 'PowerGroup'
The Easysoft ODBC-MongoDB Driver also supports parameterized updates. Here’s an example of doing this in Perl:
my $sth = $dbh->prepare('UPDATE Customers SET Surname = \'Jones\' WHERE CompanyName = ?') or die "Can't prepare statement: $DBI::errstr"; $sth->execute('PowerGroup');
-
To delete a MongoDB record, use
DELETE
. For example:-- Delete (mark inactive) a bank account DELETE FROM Customers WHERE CompanyName = 'PowerGroup'
The Easysoft ODBC-MongoDB Driver also supports parameterized deletes. Here’s an example of doing this in Python:
sql = "DELETE FROM Customers WHERE CompanyName = ?" cursor.execute(sql, 'PowerGroup')