title: How to add multiple entries to Mongodb document at once using MongoEngine in Flask?
body: <p>How can I add several entries to a document at once in Flask using MongoEngine/Flask-MongoEngine?</p>
  
  <p>I tried to iterate over the dictionary that contains my entries. I simplified the example a bit, but originally the data is a RSS file that my Wordpress spits out and that I parsed via <code>feedparser</code>. </p>
  
  <p>But the problem obviously is that I cannot dynamically generate variables that hold my entries before being saved to the database.</p>
  
  <p>Here is what I tried so far.</p>
  
  <p><em>How can I add the entries to my MongoDB database in bulk?</em></p>
  
  <pre><code># model
  class Entry(db.Document):
      created_at = db.DateTimeField(
          default=datetime.datetime.now, required=True),
      title = db.StringField(max_length=255, required=True)
      link = db.StringField(required=True)
  
  # dictionary with entries
  e = {'entries': [{'title': u'title1',
                    'link': u'http://www.me.com'
                    },
      {'title': u'title2',
       'link': u'http://www.me.com/link/'
       }
  ]
  }
  
  # multiple entries via views
  i = 0
  while i&lt;len(e['entries']):
        post[i] = Entry(title=e['entries'][i]['title'], link=e['entries'][i]['title'])
        post[i].save();
        i += 1
  </code></pre>
  
  <p>Edit 1:</p>
  
  <p>I thought about skipping the variables alltogether and translate the dictionary to the form that <code>mongoengine</code> can understand.</p>
  
  <p>Because when I create a list manually, I can enter them in bulk into MongoDB:</p>
  
  <pre><code>newList = [RSSPost(title="test1", link="http://www.google.de"),
              RSSPost(title="test2", link="http://www.test2.com")]
  
  RSSPost.objects.insert(newList)
  </code></pre>
  
  <p>This works, but I could not translate it completely to my problem.</p>
  
  <p>I tried</p>
  
  <pre><code>f = []
  
  for x in e['entries']:
      f.append("insert " + x['link'] + " and " + x['title'])
  </code></pre>
  
  <p>But as you see I could not recreate the list I need.</p>
  
  <p><em>How to do it correctly?</em></p>