小编Yas*_*ngh的帖子

如何使用 python 在 MongoDB 中创建模式?

我对 MongoDB 还很陌生。我将尽力在这里总结一下当前的问题。我已经提供了三种不同的 JSON 模式,我想使用 python 在 MongoDB 中创建此模式。我的代码如下:

import pymongo

client = pymongo.MongoClient("mongodb://127.0.0.1:27017/")

mydb=client['UserDetails']

information = mydb.Userinformation

user_schema = {

    'firstName': {
        'type': 'string',
        'minlength': 1,
        'required': True,
        'coerce': str.capitalize
    },
    'lastName': {
        'type': 'string',
        'minlength': 1,
        'required': True,
        'coerce': str.capitalize
    },
    'email': {
        'type': 'string',
        "required": False,
        "coerce": str,
        "nullable": True
    },
    'phoneNo': {
        'type': 'integer',
        'required': True,
        'unique': True
    },
    'userId': {
        'type': 'integer',
        'required': True,
        'unique': True
    },
    'patientId': {
        'type': 'integer',
        'required': True,
        'unique': True …
Run Code Online (Sandbox Code Playgroud)

python schema json mongodb

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

json ×1

mongodb ×1

python ×1

schema ×1