PyMongo $addToSet not working
<p>So i am using <code>pymongo==3.2.1</code> and <code>Mongo 3.2</code> but for some reason my <code>$addToSet</code> (to avoid duplicates) is not working.</p>

<p>I made sure my <code>checked_on</code> timestamp matched like for example <code>ISODate("2016-04-21T00:00:00.000Z")</code></p>

<p>My structure is like this:</p>

<pre><code>{
    "_id": ObjectID("57062e357e254255a531165e"),
    "availability": [
        {
            "checked_on": ISODate("2016-04-21T00:00:00.000Z"),
            "days": [
                {
                    "available": false,
                    "day": ISODate("2016-04-29T00:00:00.000Z")
                },
                {
                    "available": false,
                    "day": ISODate("2016-04-30T00:00:00.000Z")
                }
            ]
        }
    ],
    "is_active": true,
    "updated_on": ISODate("2016-04-21T13:41:12.449Z")
}
</code></pre>

<p>I have tried both:</p>

<pre><code>result = self.db[self.collection_name].update_one(
    {'_id': doc['_id']},
    {
        '$addToSet': {
            'availability': {
                '$each': [
                    {
                        'checked_on': datetime.datetime(
                            date.year, date.month, date.day
                        ),
                        'days': meta['availability']
                    }
                ]
            }
        },
        '$set': {
            'is_active': is_active, 'updated_on': date
        }
    }
)
</code></pre>

<p>and </p>

<pre><code>result = self.db[self.collection_name].update_one(
    {'_id': doc['_id']},
    {
        '$addToSet': {
            'availability': {
                'checked_on': datetime.datetime(
                    date.year, date.month, date.day
                ),
                'days': meta['availability']
            }
        },
        '$set': {
            'is_active': is_active, 'updated_on': date
        }
    }
)
</code></pre>

<p>But duplicates keep appearing, what am i doing wrong?</p>