0
我使用python 3.4.2,eve 0.7,flask 0.12和MongoDB作爲我的數據庫。使用MongoDB的ObjectId獲取資源時返回404?
這裏是我的前夕架構代碼:
'item_title': 'abc',
'id_field': 'ObjectId',
'item_lookup_field': 'ObjectId',
'item_url': r'regex("[\w]+")',
'query_objectid_as_string': True
當我嘗試使用Mongo的對象ID獲取資源,它會返回404
'item_title': 'abc',
'id_field': 'custom_field',
'item_lookup_field': 'custom_field',
'item_url': r'regex("[\w]+")',
'query_objectid_as_string': True
當我使用任何其他自定義字段,它工作正常。 我也試過下面的代碼。也返回404
'item_title': 'abc',
#'id_field': 'ObjectId',
#'item_lookup_field': 'ObjectId',
'item_url': r'regex("[\w]+")',
'query_objectid_as_string': True
'id_field'設置只是設置所使用的ID字段的名稱。這些資源是否有一個名爲ObjectId的字段?如果您在發佈後更改了它們,它們可能還沒有。 – gcw
沒有資源沒有字段名稱對象標識。它有字段'_id' –
這就是爲什麼你不能獲取資源。你的'item_lookup_field'設置爲'ObjectId',但它不存在。嘗試從現在開始使用這些設置創建新資源,新資源應該具有預期的ID字段並按照查找所需工作。 – gcw