nanomongo.util

nanomongo.util.check_spec(cls, spec)[source]

Check the query spec for given class and log warnings. Not extensive, helpful to catch mistyped queries.

  • Dotted keys (eg. {'foo.bar': 1}) in spec are checked for top-level (ie. foo) field existence
  • Dotted keys are also checked for their top-level field type (must be dict or list)
  • Normal keys (eg. {'foo': 1}) in spec are checked for top-level (ie. foo) field existence
  • Normal keys with non-dict queries (ie. not something like {'foo': {'$gte': 0, '$lte': 1}}) are also checked for their data type
class nanomongo.util.RecordingDict(*args, **kwargs)[source]

A dict subclass modifying dict.__setitem__() and dict.__delitem__() methods to record changes internally in its __nanodiff__ attribute.

check_can_update(modifier, field_name)[source]

Check if given modifier field_name combination can be added. MongoDB does not allow field duplication with update modifiers. This is to be used with methods add_to_set()

clear_other_modifiers(current_mod, field_name)[source]

Given current_mod, removes other field_name modifiers, eg. when called with $set, removes $unset and $addToSet etc. on field_name.

get_sub_diff()[source]

Find fields of RecordingDict type, iterate over their diff and build dotted keys to be merged into top level diff.

reset_diff()[source]

Reset __nanodiff__ recursively. To be used after saving diffs. This does NOT do a rollback. Reload from db for that.

class nanomongo.util.NanomongoSONManipulator(as_class, transforms=None)[source]

A pymongo SON Manipulator used on data that comes from the database to transform data to the document class we want because as_class argument to pymongo find methods is called in a way that screws us.

  • Recursively applied, we don’t want that
  • __init__ is not properly used but rather __setitem__, fails us

JIRA: PYTHON-175 PYTHON-215