2017-07-27 99 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