dbtools API Reference

Utility classes/functions for using MongoDB

class moastro.dbtools.DotReachable[source]

Formats outgoing documents as ReachableDoc, so that embedded documents can be addressed with dot notation directory.

e.g., doc[‘firstkey.secondkey’] = value

class moastro.dbtools.ReachableDoc(*args, **kwargs)[source]

ReachableDoc manipulates overrides dict __getitem__ behaviour to allow embedded documets to be accessed with dot notation in the keys.

moastro.dbtools.make_connection(server=None, url='localhost', port=27017)

Factory for MongoDB connections.

This function will attempt to connect to the named server, and fall back to the URL and port settings if a server is not named.


server : str

Name of the server, matching that in the .moastro.json file.

url : str

URL/hostname of the MongoDB server.

port : int

Port that the MongoDB server connects on.


connection : obj

A PyMongo connection instance.

moastro.dbtools.reach(doc, key)[source]

Returns a value from an embedded document.

>>> embeddedDict = {"first": {"second": "gold!"}}
>>> reach(embeddedDict, "first.second")

doc : dict compatible

Document returned by a MongoDB cursor

key : str

Key pointing to value being sought. Can use the MongoDB dot notation to refer to values in embedded documents. Root level keys (without dots) are perfectly safe with this function.


docstring for test_reach

Page Contents