Request array of json documents (disable item reference) from MongoDB using python eve

馋奶兔 提交于 2019-12-23 04:04:16

问题


Using Python eve framework, Is there any way to get response shown in first json type which is array of objects like shown in example?. I have tried to disable HATEOAS like it says here. Some View Applications use direct fetching on model and collections based on it, such as Backbone NodeJS data handler.

 [
  {
    "_id": "526c0e21977a67d6966dc763",
    "question": "1",
    "uk": "I heard a bloke on the train say that tomorrow's trains will be delayed.",
    "us": "I heard a guy on the train say that tomorrow's trains will be delayed."
  },
  {
    "_id": "526c0e21977a67d6966dc764",
    "question": "2",
    "uk": "Tom went outside for a fag. I think he smokes too much!",
    "us": "Tom went outside for a cigarette. I think he smokes too much!"
  }
]

Instead of returning the JSON object with _items key like it shows:

{
  "_items":[
            {
              "_id": "526c0e21977a67d6966dc763",
              "question": "1",
              "uk": "I heard a bloke on the train",
              "us": "I heard a guy on the train"
            },
            {
              "_id": "526c0e21977a67d6966dc764",
              "question": "2",
              "uk": "Tom went outside for a fag. I think he smokes too much!",
              "us": "Tom went outside for a cigarette. I think he smokes too much!"
            }
   ]
}

回答1:


This is currently not possible, as the response payload is built as a dictionary in which several keys might appear (pagination data, HATOEAS links, and actual documents).

In theory we could add a new configuration option which would switch to a list-formatted (and simplified) layout. Should consider all the consequences though, so no promises, but consider opening a ticket.



来源:https://stackoverflow.com/questions/35160423/request-array-of-json-documents-disable-item-reference-from-mongodb-using-pyth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!