Skip to content

Instantly share code, notes, and snippets.

@jorgebastida
Created August 22, 2012 11:16
Show Gist options
  • Save jorgebastida/3424560 to your computer and use it in GitHub Desktop.
Save jorgebastida/3424560 to your computer and use it in GitHub Desktop.
class Comment(db.EmbeddedDocument):
...
visibility = db.IntField(default=0)
mentions = db.ListField(db.GenericReferenceField())
class Message(db.Document):
...
comments = db.ListField(db.EmbeddedDocumentField(Comment))
# I want the list of Messages that have comments that ment a particular user and they are visible (the comments):
user = User.objects.get( ... )
Message.objects(__raw__={'comments': {'$elemMatch': {'visibility': 0,'mentions': {'_cls': 'User', '_ref': user.to_dbref()}}}})
@jorgebastida
Copy link
Author

Raw query:
{'_types': 'Message',
'comments': {'$elemMatch': {'mentions': {'_cls': 'User',
'_ref': DBRef('user', ObjectId('500d896da3c67371da000009'))},
'visibility': 2}}}

@atroche
Copy link

atroche commented Sep 2, 2012

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment