2

For some queries in my application, I am using a SON manipulator to conveniently render database output. In some other cases, I just want the raw data.

So I add my manipulator thus:

db.add_son_manipulator(Renderer())

And here's my Renderer:

class Renderer(pymongo.son_manipulator.SONManipulator):
    def transform_outgoing(self, son, collection):
        rendered_data = {}

        for field in son:
            try:
                rendered_data[field] = son[field]['value']
            except (KeyError, TypeError):
                rendered_data[field] = son[field]

        return rendered_data

Question: How do I remove the manipulator from the database class instance for cases when I don't want my data transformed?

sssilver
  • 2,549
  • 3
  • 24
  • 34

1 Answers1

0

EDITED

Seems it is impossible to do in a normal way (no API method exists for that purpose). Instead I should have another database object with no manipulator and use it when I don't need to transform the data (probably would work even faster).

Serge
  • 1,947
  • 3
  • 26
  • 48