Created
August 22, 2012 11:16
-
-
Save jorgebastida/3424560 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Raw query:
{'_types': 'Message',
'comments': {'$elemMatch': {'mentions': {'_cls': 'User',
'_ref': DBRef('user', ObjectId('500d896da3c67371da000009'))},
'visibility': 2}}}