title: Flask-Restful: Passing list into MongoDB via POST request
body: <p>I'm building an API for a new web service using Python, Flask-Restful w/ pymongo. </p>
  
  <p>A sample MongoDB document <strong>should</strong> look like this:</p>
  
  <pre><code>{ domain: 'foobar.com',
    attributes: { web: [ akamai,
                         google-analytics,
                         drupal,
                         ... ] } }
  </code></pre>
  
  <p><br>
  <strong>The imports:</strong></p>
  
  <pre><code>from flask import Flask, jsonify
  from flask.ext.restful import Api, Resource, reqparse
  from pymongo import MongoClient
  </code></pre>
  
  <p><br>
  <strong>The class:</strong></p>
  
  <pre><code>class AttributesAPI(Resource):
  def __init__(self):
      self.reqparse = reqparse.RequestParser()
      self.reqparse.add_argument('domain', type = str, required = True, help = 'No domain given', location='json')
      self.reqparse.add_argument('web', type = str, action='append', required = True, help = 'No array/list of web stuff given', location = 'json')
      super(AttributesAPI, self).__init__()
  
  def post(self):
      args = self.reqparse.parse_args()
      post = db.core.update(  {'domain': args['domain']},
                              {'$set':{'attr': {  'web': args['web'] }}},
                              upsert=True)
      return post
  </code></pre>
  
  <p><br>
  <strong>When I CURL post, I use this:</strong></p>
  
  <pre><code>curl -i -H "Content-Type: application/json" -X POST -d '{"domain":"foobar", "web":"akamai", "web":"drupal", "web":"google-analytics"}' http://localhost:5000/v1/attributes
  </code></pre>
  
  <p><br>
  <strong>However, this is what gets saved in my document:</strong></p>
  
  <pre><code>{ "_id" : ObjectId("5313a9006759a3e0af4e548a"), "attr" : { "web" : [  "google-analytics" ] }, "domain" : "foobar.com"}
  </code></pre>
  
  <p><br>
  It only stores the last value given in the curl for 'web'. I also tried to use the CLI command with multiple -d params as described in the <a href="http://flask-restful.readthedocs.org/en/latest/reqparse.html#basic-arguments" rel="nofollow">reqparse documentation</a> but that throws a 400 - BAD REQUEST error. </p>
  
  <p>Any ideas how why it is only saving the last value instead of all values as a list?</p>