使用integer作为_id类型返回http400进行项查找

2024-09-25 10:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

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

当我试图使用这个URL:http://xxxxxxx/promotions/1485919019667访问一个条目(它存在于数据库中)时,它返回htp404。在

我想知道是否不可能使用ObjectID以外的类型作为\u id?在

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
        }
    }
}

Tags: idtruehttpurl类型stringtitletype
1条回答
网友
1楼 · 发布于 2024-09-25 10:25:13

你看过文档中的Handling custom ID fields了吗?引用该页标题:

However, you might have collections where your unique identifier is not and ObjectId, and you still want individual document endpoints to work properly. Don’t worry, it’s doable, it only requires a little tinkering.

本教程涵盖了UUID字段,但对任何自定义类型都很有用。在

相关问题 更多 >