Reputation: 1836
I want to display a user's feed that contains documents from both post
and activity
collections. However, I only want to display a certain numbers of posts
and activites
documents and only show more when user scroll mouse to the bottom of the page. The problem is I don't know how to use limit
operator on two separate collections.
There is one way to go about this is (for example, if I want to limit to 20 documents to show on user page) to query for 10 documents on post
and 20 documents on activity
and then sort them to get 20 ordered documents. But this introduces performance issue.
How could you go about this situation?
Upvotes: 0
Views: 75
Reputation: 36794
All operations in MongoDB tend to work on one collection only, and so do queries, and hence limit. You will have to query 20 entries from each collection, and sort in your application.
Upvotes: 2