title: How to create schema in MongoDB using python?
body: <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>The above code line gives me an error as below</p>
  
  <p>TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping</p>
  
  <p>information.insert_one(user_schema)</p>
  
  <p>And trying this gives me an error </p>
  
  <p>cannot encode object: method 'capitalize' of 'str' objects, of type: class 'method_descriptor'</p>
  
  <p>Any help how to create this schema in mongoDB using python will be much appreciated! </p>