我有一个运行在服务器上的mongod实例,上面有数据库 我正在尝试将eve设置为数据库的REST http API,以便简单地响应GET请求。
如果我使用mongod REST接口请求http://92.51.132.110:28017/clockrefdb/test/rows,我会得到:
{
"offset" : 0,
"rows": [
{ "_id" : { "$oid" : "5745ef6494aef075d127f1d0" }, "timestamp" : { "$date" : "2016-05-25T22:31:00.035+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ,
{ "_id" : { "$oid" : "5747034194aef04e87df598d" }, "timestamp" : { "$date" : "2016-05-26T18:08:01.209+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ,
{ "_id" : { "$oid" : "5747050094aef04fe7aa7c14" }, "timestamp" : { "$date" : "2016-05-26T18:15:28.576+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ,
{ "_id" : { "$oid" : "5747050b94aef04ff397c81f" }, "timestamp" : { "$date" : "2016-05-26T18:15:39.779+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ,
{ "_id" : { "$oid" : "5747052694aef050096e5c71" }, "timestamp" : { "$date" : "2016-05-26T18:16:06.635+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] } ,
{ "_id" : { "$oid" : "57470a1694aef0536bf1d712" }, "timestamp" : { "$date" : "2016-05-26T18:37:10.022+0200" }, "frequencies" : [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ] }
],
"total_rows" : 6 ,
"query" : {} ,
"millis" : 0
}
db中的文档中哪些是正确的值。 现在如果我运行前夕和设置:
DOMAIN = { 'test':{} }
MONGO_HOST = 'localhost'
MONGO_PORT = 27017
MONGO_USERNAME = 'user'
MONGO_PASSWORD = 'passw'
MONGO_DBNAME = 'clockrefdb'
RESOURCE_METHODS = ['GET']
使用默认脚本运行eve:
python run.py
curl --header "Accept:application/json" "http://127.0.0.1:5000/test/57470a1694aef0536bf1d712"
我明白了:
{
"_created": "Thu, 01 Jan 1970 00:00:00 GMT",
"_etag": "c020b57efefeb92a74f5d07875d9234e3aef077a",
"_id": "57470a1694aef0536bf1d712",
"_links": {
"collection": {
"href": "test",
"title": "test"
},
"parent": {
"href": "/",
"title": "home"
},
"self": {
"href": "test/57470a1694aef0536bf1d712",
"title": "Test"
}
},
"_updated": "Thu, 01 Jan 1970 00:00:00 GMT" }
两件事情很突出:错误的日期和缺失的表格。 你怎么看这引起了这个错误的数据读取? 我想我错过了一些重要的步骤 有什么想法吗?
答案 0 :(得分:3)
Eve只会公开映射到已知域架构的字段。这样做是为了让API维护者完全控制暴露的字段集,因为他/她可能不希望暴露整个文档。
所以你有两个选择。您可以为端点设置适当的域架构,例如:
DOMAIN = {
'test': {
'schema': {
'offset': {'type': 'integer'},
'rows': {
'type': 'list',
'schema': {'type': 'dict', 'schema': ..., }
},
...
}
}
}
或者您可以设置全局ALLOW_UNKNOWN = True
。最后一个设置也可用作端点级设置。
有待进一步参考,请参阅: