$jsonSchema 属性的嵌套模式 'description' 必须是一个对象",'code': 14, 'codeName': 'TypeMismatch'

问题描述 投票:0回答:0

所以我正在尝试使用

pymongo
在 python 中创建 MongoDB 验证器。

这是我的模式的样子:

user_validator = {
        "$jsonSchema":{
            "bsonType": "object",
            "required": ["user_email", "user_name", "rules"],
            "properties":{
                "user_email": {
                    "bsonType": "string",
                    "description": "must be string and is required"
                },
                "user_name":{
                    "bsonType": "string",
                    "description": "must be a string and is required"
                },
                "rules":{
                        "bsonType": "array",
                        "items":{
                            "bsonType": "object",
                            "properties": {
                                "name":{
                                    "bsonType": "string",
                                    "description": "must be string"
                                },
                                "commit_hashes":{
                                    "bsonType": "array",
                                    "items":{
                                        "bsonType": "object",
                                        "properties": {
                                            "hash": {
                                                "bsonType": "string",
                                                "description": "must be string"
                                            },
                                            "date": {
                                                "bsonType": "string",
                                                "description": "must be string"
                                            }
                                        },
                                        "description": "must be object"
                                    },
                                    "description": "must be array"
                                }
                            },
                            "description": "must be Object"
                        }
                        },
                        "description": "must be array of objects and is required" 
                    }
                },
                "description": "must be array of objects and is required"
            }

运行代码后我得到这个错误:

pymongo.errors.OperationFailure: Parsing of collection validator failed :: caused by :: Nested schema for $jsonSchema property 'description' must be an object, full error: {'ok': 0.0, 'errmsg': "Parsing of collection validator failed :: caused by :: Nested schema for $jsonSchema property 'description' must be an object", 'code': 14, 'codeName': 'TypeMismatch'}

而且我不太确定为什么会这样。有人能告诉我这是怎么回事吗?

mongodb pymongo
© www.soinside.com 2019 - 2024. All rights reserved.