Skip to content

Instantly share code, notes, and snippets.

@namlook
Created September 26, 2013 12:30
Show Gist options
  • Save namlook/6713491 to your computer and use it in GitHub Desktop.
Save namlook/6713491 to your computer and use it in GitHub Desktop.
MongoKit simple inheritance example 3
from mongokit import ObjectId, Connection
connection = Connection()
@connection.register
class UserNugget(Core):
__collection__ = "user_nuggets"
structure = {
"url": unicode,
"topics": [unicode],
"user_id": unicode
}
required_fields = ["url", "topics", "user_id"]
def save(self, *args, **kwargs):
super(self, UserNugget).save(*args, **kwargs)
nugget = self.db.Nugget.find_one({"url": self.url})
if not nugget:
nugget = self.db.Nugget(url=url, discoverer=self.user_id)
nugget.save()
self.db.Nugget.collection.update({"url": self.url}, {"$addToSet": {"topics": {"$each": self.topics}}, "$inc": 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment