Search code examples
pythonmongodbeve

Proper way to suppress a field from every element in a collection in python-eve


I would like to prevent a certain largish field in a collection of documents from being returned as part of the basic resource request in an eve app. What is the proper way of doing this? I was thinking of using an on_fetch hook but thought maybe there was some way of specifying this in the schema instead.


Solution

  • Projections can also be used to Limit the Fieldset Exposed by the API:

    When setting the datasource property for any given resource endpoint it is possible to explicitly exclude fields (of media type, but also of any other type really) from default responses:

    people = {
        'datasource': {
            'projection': {'image': 0}
        },
        ...
    }