3

I have started using Python-Eve to access an existing MongoDB database I have from another project. I was successful in getting correct HTTP 200 responses for queries to specific documents in the database, but I was puzzled by the fact that they did not contain any information other than the following:

"_items": [
{
  "_updated": "Thu, 01 Jan 1970 00:00:00 GMT",
  "_etag": "<some etag>",
  "_created": "Thu, 01 Jan 1970 00:00:00 GMT",
  "_id": "<some ObjectID>",
}

I have since discovered that I do get the data I want if I specify the entries in a schema in Eve's settings.py file.

I am assuming that this is intended behavior, and that it might have to do something with validation. But I am wondering if there is a way to turn it off. My primary goal was to quickly get a Python REST API up and running for an existing database, specifying the schema is an unnecessary hassle with that goal in mind. I don't mind doing it for now, but I'm just wondering for future applications.

Fulco
  • 284
  • 1
  • 3
  • 16

1 Answers1

5

Try setting ALLOW_UNKNOWN to True. Just make sure that your endpoint is read-only, unless you want to allow unknown fields/unvalidated documents in the datastore.

Nicola Iarocci
  • 6,606
  • 1
  • 20
  • 33
  • 1
    That works, thanks! I did come across this option in the documentation, but it only mentions its effect with regards to POST and PATCH commands. My case might be a useful addition to the docs. Otherwise, searching for the answer has helped me learn about the data validation features of Eve, and validation in general! – Fulco Jan 08 '16 at 13:50
  • Yeah I agree that the docs could use an update. Feel free to submit a pull request if you feel like doing it (or I will do it in due time) – Nicola Iarocci Jan 08 '16 at 15:41