Instantly share code, notes, and snippets.

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