The module class provides methods, global properties, exceptions, constructors, and type objects to be used by all connections created in the module.
connect(connection string|connection parameters)Creates a new connection to the database.
Arguments
connection string
"parameter=value;parameter=value"connection parameters
Connection parameters
Return value
connection object.Code sample
# establising a connection using a connection string
connection1 = devart.mongodb.connect("Server=your_server;Database=your_database;Username=your_username;Password=your_password;ClientLibary=path_to_libmongoc;BSONLibrary=path_to_libbson")
# establising a connection using named parameters
connection2 = devart.mongodb.connect(
Server="your_server",
Database="your_database",
Username="your_username",
Password="your_password",
ClientLibary="path_to_libmongoc",
BSONLibrary="path_to_libbson"
)
license.activate(activation key)Activates a license.
Arguments
activation key
Remarks
license.deactivate()Deactivates a license.
Arguments
Remarks
apilevel"2.0".threadsafety2 meaning threads may share the module and connections.paramstyle"named" indicating that the module supports named style parameters, such as ...WHERE name=:name.connection_poollicense.summaryWarningWarning exception is a subclass of the Python Exception class.Errorexcept statement. The Error exception is a subclass of the Python Exception class.InterfaceErrorInterfaceError exception is a subclass of Error.DatabaseErrorDatabaseError exception is a subclass of Error.DataErrorDataError exception is a subclass of DatabaseError.OperationalErrorDatabaseError.IntegrityErrorIntegrityError exception is a subclass of DatabaseError.InternalErrorInternalError exception is a subclass of DatabaseError.ProgrammingErrorProgrammingError exception is a subclass of DatabaseError.NotSupportedErrorrollback() on a connection that doesn't support transactions or has transactions turned off. The NotSupportedError exception is a subclass of DatabaseError.ExceptionWarning
Error
InterfaceError
DatabaseError
DataError
OperationalError
IntegrityError
InternalError
ProgrammingError
NotSupportedError
datetime module objects.
Date(year, month, day)Creates an object that holds a date value.
Arguments
year
month
day
int that specify the year, month, and day.Return value
datetime.date object.Time(hour, minute, second[, timezone])Creates an object that holds a time value.
Arguments
hour
minute
int that specify hours and minutes.second
int value that specifies seconds or a float value that specifies seconds and microseconds.timezone
datetime.tzinfo that specifies a timezone. The value can be None.Return value
datetime.time object.Timestamp(year, month, day[, hour[, minute[, second[, timezone]]]])Creates an object that holds a timestamp value.
Arguments
year
month
day
int that specify the year, month, and day.hour
minute
int that specify hours and minutes.second
int value that specifies seconds or a float value that specifies seconds and microseconds.timezone
datetime.tzinfo that specifies a timezone. The value can be None.Return value
datetime.datetime object.DateFromTicks(ticks)Creates an object that holds a date value from the given ticks value (the number of seconds since the Unix epoch). For more information, see the time module in the standard Python documentation.
Arguments
ticks
float that specifies number of seconds since the Unix epoch.Return value
datetime.date object.TimeFromTicks(ticks)Creates an object that holds a time value from the given ticks value (number of seconds since the Unix epoch). For more information, see the time module in the standard Python documentation.
Arguments
ticks
float that specifies number of seconds since the Unix epoch.Return value
datetime.time object.TimestampFromTicks(ticks)Creates an object that holds a timestamp value from the given ticks value (number of seconds since the Unix epoch). For more information, see the time module in the standard Python documentation.
Arguments
ticks
float that specifies number of seconds since the Unix epoch.Return value
datetime.datetime object.Binary(value)Creates an object that holds binary data.
addtypecast() cursor method to define a data type cast rule to use when fetching data from the cursor. They can also be used to determine the Python types of the result columns returned by the execute*() cursor methods.
STRINGThis type object describes string-based columns in a database.
BINARYThis type object describes binary columns in a database.
NUMBERThis type object describes numeric columns in a database.
DATETIMEThis type object describes date/time columns in a database.
ROWIDThis type object describes the row ID column in a database.
Code sample
cursor.execute("select column1 from table1")
# check if the first column in the result set is string-based so that its value can be safely treated as `str`
if cursor.description[0].type_code in mongodb.STRING:
# do something
binaryThis type object describes an object that holds binary data. By default, this type object is used to fetch BLOB-based columns from the cursor. You can also create a binary object using the Binary() constructor.
Attributes
value
bytes that represents binary data. This is a read/write attribute that accepts values of type str, bytes, bytearray, array.array, and binary.