Very simple Python interface to MongoDB. Based on pymongo, this class
provides methods to get and set default databases and collections, to
insert documents, query collections, and clear all documents in a
collection.
The query() method encapsulates MangoDB native methods find() and
find_one(). The query() method makes it very convenient to to request
only particular sets of fields (columns in relational terms).
Example:
|
|
__init__(self,
host='localhost',
ssl_keyfile=None,
dbName='test',
collection='test_collection',
port=27017,
user=None,
pwd='')
Create a connection to the MongoDB demon on the given host/port. |
source code
|
|
|
|
setDB(self,
dbName)
Establish a default database within MongoDB for subsequent calls to
other methods of this class. |
source code
|
|
|
String
|
getDBName(self)
Obtain the name of the MongoDB database that is currently the default
for calls to methods of this class. |
source code
|
|
|
|
setCollection(self,
collName)
Establish a default MongoDB collection for subsequent calls to other
methods of this class. |
source code
|
|
|
String
|
getCollectionName(self)
Obtain the name of the MongoDB collection that is currently the
default for calls to methods of this class. |
source code
|
|
|
{generator<ResultDict>}
|
query(self,
mongoQuery,
colNameTuple=(),
limit=0,
db=None,
collection=None)
Method for querying the database. |
source code
|
|
|
{int | None}
|
|
|
|
|
|
|
|
|
|
insert(self,
doc_or_docs,
db=None,
collection=None)
Insert the given dictionary into a MongoDB collection. |
source code
|
|
|
|
|
|
|
get_db(self)
Obtain current default MongoDB database object |
source code
|
|
|
|
get_collection(self)
Obtain current default MongoDB database object |
source code
|
|
|
Inherited from object:
__delattr__,
__format__,
__getattribute__,
__hash__,
__new__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__,
__subclasshook__
|