Get mongodb collection using Eve -
i have mongod instances running on server database on it.
i'm trying set eve rest http api database, simple respond requests.
if request http://92.51.132.110:28017/clockrefdb/test/rows using mongod rest interface, get:
{ "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 }
which correct values documents in db. if run eve , settings:
domain = { 'test':{} } mongo_host = 'localhost' mongo_port = 27017 mongo_username = 'user' mongo_password = 'passw' mongo_dbname = 'clockrefdb' resource_methods = ['get']
and run eve default script:
python run.py
and curl --header "accept:application/json" "http://127.0.0.1:5000/test/57470a1694aef0536bf1d712"
i get:
{ "_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" }
two things standout: wrong date, , missing table. think provoking incorrect reading of db?
guess missing important steps.
idea which?
eve expose fields mapped known domain schema. done in order allow api maintainer total control on exposed fieldset, he/she might not want whole document exposed.
so have 2 options. set proper domain schema endpoint, like:
domain = { 'test': { 'schema': { 'offset': {'type': 'integer'}, 'rows': { 'type': 'list', 'schema': {'type': 'dict', 'schema': ..., } }, ... } } }
or set global allow_unknown = true
. last setting available endpoint-level setting.
for further reference see:
Comments
Post a Comment