Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:07:48+00:00 2026-05-25T17:07:48+00:00

In my rails 3 app I use mongo and mongoid gem with 3 models:

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:07:48+00:00Added an answer on May 25, 2026 at 5:07 pm

    Got to http://mongoid.org/docs/querying.html

    Posts.where(:user_id => your_user_id).first.friends
    

    Then you can do any map on friends you want.

    So looking at your models you can do:

     Post.all_in(:user_id => [your_user.id, your_user.friends.map(&:id)].flatten )
    

    This will return all the posts of that user and his friends

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby script in my Rails app that I use to load
I'm trying to create a rails web app that does not use ActiveRecord framework
I'm in the process of converting my Rails app to use mongodb through mongoid.
Specifically, I have a number of pages in my Rails app that use the
I have written constant.rb in lib/ folder for my rails app.To use that in
I have a simple rails app and i use paperclip gem for my image
I have a Rails app that saves files in mongo. This works great and
do you use Heroku to write Ruby on Rails app? i read about from
I use sendmail to send emails from my ruby-on-rails app. I used this awesome
I'm looking to use the latest Twitter gem for a Rails app I'm working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.