Mongo errors that type needs to be array
<p>I'm trying to update push some data into a document in mongodb. The following runs fine:</p>

<pre><code>import pymongo
import bson
from bson.objectid import ObjectId

client = pymongo.MongoClient('mongodb://localhost:27351/')
db = client.db
foo = db.foo

for i in range(2):
    nm = "xxx"+str(i)
    foo.insert_one({
            "foo":"bar", 
            "name": nm, 
            "friends": i, 
            "enemies": i+10, 
            "relations":
            {
                "friends": i,
                "enemies": i+10
            }
        })
</code></pre>

<p>I can then add to one of the ducuments like so:</p>

<pre><code>foo.update_one({"name": "xxx1"},{"$push":{"comment":{"initial": "hello", "last": "world"}}})
list(foo.find())
</code></pre>

<p>It returns this:</p>

<pre><code>[{'_id': ObjectId('575f3b32f203c6069d9674ee'),
  'enemies': 10,
  'foo': 'bar',
  'friends': 0,
  'name': 'xxx0',
  'relations': {'enemies': 10, 'friends': 0}},
 {'_id': ObjectId('575f3b32f203c6069d9674ef'),
  'comment': [{'initial': 'hello', 'last': 'world'}],
  'enemies': 11,
  'foo': 'bar',
  'friends': 1,
  'name': 'xxx1',
  'relations': {'enemies': 11, 'friends': 1}}]
</code></pre>

<p>The problem is the following that errors - why?:</p>

<pre><code>foo.update_one({"name": "xxx1"},{"$push":{"relations":{"enemies": 99, "friends": 88}}})
</code></pre>

<blockquote>
  <p>WriteError: The field 'relations' must be an array but is of type
  Object in document {_id: ObjectId('575f3b32f203c6069d9674ef')}</p>
</blockquote>