title: Mongoengine documents with DataFrames
body: <p>suppose I have the following mongo model:</p>
  <pre><code>class User(Document):
      name = StringField(required=True,unique=True)
      characteristics = DictField()
  class Office(Document):
      user = ReferenceField(User)
      office= StringField(required=True,unique=True)
      salary = IntField()
  class Department(Document):
      offices = ReferenceField(Office)
      city = StringField(required=True,unique=True)
      country = StringField()
  </code></pre>
  <p>and I have the following dataframes:</p>
  <pre><code>df_users = pd.DataFrame({&quot;name&quot;:[&quot;Goku&quot;,&quot;Gohan&quot;,&quot;Piccolo&quot;], 
                           &quot;characteristics&quot;:[{&quot;a&quot;:1},{&quot;b&quot;:2},{&quot;c&quot;:3}]})
  df_office = pd.DataFrame({&quot;user&quot;:[&quot;Goku&quot;,&quot;Gohan&quot;,&quot;Piccolo&quot;],
                            &quot;office&quot;:[&quot;Earth&quot;,&quot;Pao&quot;,&quot;Namek&quot;],
                            &quot;salary&quot;:[1,2,3]})
  df_department = pd.DataFrame({&quot;offices&quot;:[&quot;Earth&quot;,&quot;Pao&quot;,&quot;Namek&quot;],
                                &quot;city&quot;:[&quot;South City&quot;,&quot;North City&quot;,&quot;nameki&quot;],
                                &quot;country&quot;:[&quot;A&quot;,&quot;B&quot;,&quot;C&quot;] })
  </code></pre>
  <p><a href="https://i.stack.imgur.com/RQCCJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RQCCJ.png" alt="F" /></a></p>
  <p>I know that I can upload those dataframes easily to a mongo collection with :</p>
  <pre><code>db.collection.insert_many(df_name.to_dict(&quot;records&quot;))
  </code></pre>
  <p>But if I do that, then Why I defined those classes User, Office, Department? I don't know if I would get and non empty answer if I do</p>
  <pre><code>User.objects(); Office.objects(), Department.objects()
  </code></pre>
  <p>I know that I can do</p>
  <p>record = User(name = &quot;Goku&quot;, characteristic = 0)
  record.save  # some command to upload to collection</p>
  <p>So, my question is, How can I upload those dataframes using the classes I defined?
  some kind of</p>
  <pre><code>df_name.apply(lambda x: Respectively_Class(**x)).insert(db.collection_name)
  </code></pre>
  <p>So when I call Respectively_Class.objects I got a non empty result?</p>