I have two MongoDB collections. One is Users
and another is Posts
. In the user collection, each document stores a list of usernames that that particular user follows. For example,
{
'username' : 'username',
'following' : ['user1', 'user2', 'user3'],
...
}
And, each document in the Posts
collection consists of an author
field. Now, in order to create a news feed, I want to show only the posts of the users that a particular user follows.
{
'content' : 'some content',
'author' : 'user1',
...
}
Can I write a query in MongoEngine (Python) such that the Posts
collection is queried and it returns all the documents in which the author
field is one of the authors from the following
list? (The list of the people that user follows) in a chronological manner.
Thank you!