nachonachoman
nachonachoman

Reputation: 852

Python Eve: fields not returned in default configuration

I am trying to leverage EVE to expose a read-only mongo document collection. The problem is none of the object fields are returned through EVE.

Trying to start as simple as possible. My mongodb 'restaurants' collection is built using a tutorial.

A quick test of the mongo database looks good:

> db.restaurants.find().limit(1).pretty()
{
        "_id" : ObjectId("584ad656b02a038949ee59cb"),
        "address" : {
                "building" : "1007",
                "coord" : [
                        -73.856077,
                        40.848447
                ],
                "street" : "Morris Park Ave",
                "zipcode" : "10462"
        },
        "borough" : "Bronx",
        "cuisine" : "Bakery",
        "grades" : [
                {
                        "date" : ISODate("2014-03-03T00:00:00Z"),
                        "grade" : "A",
                        "score" : 2
                },
                {
                        "date" : ISODate("2013-09-11T00:00:00Z"),
                        "grade" : "A",
                        "score" : 6
                },
                {
                        "date" : ISODate("2013-01-24T00:00:00Z"),
                        "grade" : "A",
                        "score" : 10
                },
                {
                        "date" : ISODate("2011-11-23T00:00:00Z"),
                        "grade" : "A",
                        "score" : 9
                },
                {
                        "date" : ISODate("2011-03-10T00:00:00Z"),
                        "grade" : "B",
                        "score" : 14
                }
        ],
        "name" : "Morris Park Bake Shop",
        "restaurant_id" : "30075445"
}

The EVE server is configured as minimal as possible:

"""Settings/Config for Eve server"""
from eve import Eve

# http://python-eve.org/config.html#global-configuration
SETTINGS = {
    'DOMAIN': {'restaurants': {}},
    'MONGO_HOST': 'localhost',
    'MONGO_PORT': 27017,
    # MONGO_USERNAME': os.environ.get(...),
    # MONGO_PASSWORD': os.environ.get(...),
    'MONGO_DBNAME': 'tutorial'
}

app = Eve(settings=SETTINGS)

if __name__ == '__main__':
    app.run(host='0.0.0.0')

This runs without errors. But by navigating to http://server/restaurants I would expect to see 25 objects returned. Instead I see the following which DOES contain the items but doesnt contain the object properties such as address, borough, cuisine, grades...

My question is: Am I wrong to expect EVE to return object attributes in the listing, and if so, what configuration do I change to enable this? I only need EVE for read-only access and will likely have a large number of collections with different schemas. I would like to avoid defining/maintaining each schema explicitly.

    {
   "_items":[
      {
         "_updated":"Thu, 01 Jan 1970 00:00:00 GMT",
         "_id":"584ad656b02a038949ee59cb",
         "_links":{
            "self":{
               "href":"restaurants/584ad656b02a038949ee59cb",
               "title":"Restaurant"
            }
         },
         "_created":"Thu, 01 Jan 1970 00:00:00 GMT",
         "_etag":"dc3b9401f2c4b0d56cfcb432c20ba163db3b0817"
      },
      {
         "_updated":"Thu, 01 Jan 1970 00:00:00 GMT",
         "_id":"584ad656b02a038949ee59cc",
         "_links":{
            "self":{
               "href":"restaurants/584ad656b02a038949ee59cc",
               "title":"Restaurant"
            }
         },
         "_created":"Thu, 01 Jan 1970 00:00:00 GMT",
         "_etag":"a426dafb6ad7096089bd97c3d48b0a8349bc33cb"
      },

Upvotes: 3

Views: 479

Answers (1)

Nicola Iarocci
Nicola Iarocci

Reputation: 6576

Try setting ALLOW_UNKNOWN to True. Since your APIs are going to be read-only, you do not risk tampering of your documents anyway.

Upvotes: 3

Related Questions