2017-07-27 103 views
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 
+0

'id_field'設置只是設置所使用的ID字段的名稱。這些資源是否有一個名爲ObjectId的字段?如果您在發佈後更改了它們,它們可能還沒有。 – gcw

+0

沒有資源沒有字段名稱對象標識。它有字段'_id' –

+0

這就是爲什麼你不能獲取資源。你的'item_lookup_field'設置爲'ObjectId',但它不存在。嘗試從現在開始使用這些設置創建新資源,新資源應該具有預期的ID字段並按照查找所需工作。 – gcw

回答

1
'id_field': '_id', # Name of field                                  
'item_lookup_field': '_id', # Name of object field ex. mongo object id here 

'query_objectid_as_string': False 

由於`query_objectid_as_string「:真它查詢數據庫作爲字符串不會反對。所以它不會找到。所以它返回404