Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2011 08:08
What would you like to do?
Pure pymongo data saving for cross-benchmarking
def save_data(self, rows):
# Mark all as 'old'
{'$set': {'old': True}}, multi=True, safe=True)
# Upsert
for row in rows:
# Add productlist key and mark as 'not old'
row['productlist'] =
row['old'] = False
resp = self.db.offers.update(
{'articlenumber': row['articlenumber'],
{'$set': row}, upsert=True, safe=True)
if resp['updatedExisting']:
updated += 1
inserted += 1
# Delete de-listed offers
for offer in self.db.offers.find(
{'productlist':, 'old': True}):
removed += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment