Mongo Update keeps adding to the the size of the collection I am running a scraper to check for this one thing to change. So I have no idea why my mongo data base keeps growing when all I do is an update on this single data.

I only have one item in the database, with a post_id : 1. In my code all I am doing is updating it. (python)

client = MongoClient(DB_URL)
db = client.chatScrape

collection = db.posts

#insert scraped data
result = collection.update({'post_id' : 1}, scraped, upsert = True)

client.close()


So after the first execution I get

&gt; db.posts.find().count()
&gt; 1


But after an hour or so I get

&gt; db.posts.find().count()
&gt; 2


After about a week or so, the number grows to 10+. So what is going on here. Shouldn't update only modify one item and not make more?
I'd hazard a guess that your code is running the upsert command fairly quickly. It may depend on your MongoDB version, but on the latest version an update command which does not specify update modifiers will just overwrite the entire document, which involves deleting and re-writing it. 

It seems likely that in between another upsert operation, a second upsert is run and when it sees no document it inserts a new one. In this case you might want to look at not updating the entire document. 

You could also look into using a unique index and a little re-try logic which might work for you based on how infrequently this appears to be happening.