我的设置如下所示,其中主要标识符_id使用整数类型。

当我尝试使用以下URL访问项目(该项目在db中存在)时,它返回HTTP 404。

我想知道是否不能为_id使用ObjectID以外的类型?

promotions = {
    'item_title': 'promotion',
    'item_url' : 'regex("[\d]+")',
    'item_lookup': True,
    'schema': {
        '_id': {
            'type': 'integer',
            'minlength': 13,
            'maxlength': 13,
            'required': True,
            'unique': True
        },
        'category': {
            'type': 'string',
            'allowed': ["MARKETPLACE", "ELAUGETS", "FASHNESS", "FRINKS", "TRENTER", "OTHERS"]
        },
        'card_id': {
            'type': 'string',
            'minlength': 1,
            'maxlength': 50
        },
        'title': {
            'type': 'string',
            'minlength': 5,
            'maxlength': 200,
            'required': True
        },
        'description': {
            'type': 'string',
            'minlength': 5,
            'maxlength': 2500,
            'required': True
        }
    }
}

最佳答案

您是否看过文档中的Handling custom ID fields?从该页面的标题引用:


  但是,您可能有一个集合,其中的唯一标识符不是,而ObjectId仍然是唯一的,并且您仍然希望各个文档端点正常工作。不用担心,这是可行的,只需要稍作修改即可。


本教程涵盖了UUID字段,但实际上对任何自定义类型都有好处。

关于python - 使用整数作为_id的类型为item_lookup返回HTTP 400,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42540255/

10-15 01:55
查看更多