我正在尝试利用EVE来展示一个只读的mongo文档集合。 问题是没有任何对象字段通过EVE返回。
尽量开始尝试。 My mongodb 'restaurants' collection is built using a tutorial
对mongo数据库的快速测试看起来不错:
> 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"
}
EVE服务器配置为尽可能小:
"""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')
这样运行没有错误。但是通过导航到http://server/restaurants我希望看到返回25个对象。相反,我看到以下哪些包含物品,但不包含对象属性,如地址,行政区,美食,等级......
我的问题是:我错误地期望EVE在列表中返回对象属性,如果是,我会更改哪些配置来启用它?我只需要EVE进行只读访问,并且可能会有大量具有不同模式的集合。我想避免明确定义/维护每个模式。
{
"_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"
},
答案 0 :(得分:3)
尝试将ALLOW_UNKNOWN
设为True
。由于您的API将是只读的,因此无论如何都不会冒险篡改您的文档。