Skip to content

Instantly share code, notes, and snippets.

@tobami
Created February 18, 2011 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobami/833407 to your computer and use it in GitHub Desktop.
Save tobami/833407 to your computer and use it in GitHub Desktop.
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