Retrieve data from a collection(mongo),modify the returned object and insert it into another mongo collection
<pre><code>{
        "name" : "XYZ",
        "phone" : 12345,
        "emp_id" : 9999,
        "sal" : 5000
}
</code></pre>

<p>I want to add data on this record and store it into another database. I have tried this:</p>

<pre><code>db=connection.testing

results=db.test.find({"name":"XYZ"})

for i in results:

    i.append('dept':'Marketing')
    db.test.insert_one(i) 

(please ignore the insertion being done on the same connection)

Error:    i.append('dept':'Marketing')

                         ^
SyntaxError: invalid syntax
</code></pre>

<p>How to add data in the dictionary form or JSON form?</p>

<p>since <code>i</code> in your example seems to be a dictionary, you most likely need something like <code>i.update({'dept': 'Marketing'})</code> or <code>i['dept']='Marketing'</code> in order to introduce new key/value pair </p>

python mongodb pymongo