In my rails 3 app I use mongo and mongoid gem with 3 models: (users, friendship, posts).
I need to grab all posts that are from a specific user and his followings.
In traditional rails db will be something like:
Posts.find(:all, :conditions => ["user_id in (?)", friends.map(&:id).push(self.id)], :order => "created_at desc")
How can i do that in mongo?
Actually I don’t know how to use something like “map” and “push”.
Thanks in advance!
Got to http://mongoid.org/docs/querying.html
Then you can do any map on friends you want.
So looking at your models you can do:
This will return all the posts of that user and his friends