I'm fairly new to MongoDB. I'll try my best to summarize the problem at hand here. I've been provided three different JSON schemas and i want to create this schemas in MongoDB using python. My code is as follows:
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
},
'age': {
'type': 'integer'
},
"userStatus": {
"type": "integer",
"nullable": True
}
}
information.insert_many(user_schema)
The above code line gives me an error as below
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
information.insert_one(user_schema)
And trying this gives me an error
cannot encode object: method 'capitalize' of 'str' objects, of type: class 'method_descriptor'
Any help how to create this schema in mongoDB using python will be much appreciated!