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 3501476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:51:50+00:00 2026-05-18T12:51:50+00:00

how do you retrieve an array of IDs in Mongoid ? arr=[id1,id2] User.where(:id=>arr) You

  • 0

how do you retrieve an array of IDs in Mongoid?

arr=["id1","id2"]
User.where(:id=>arr)

You can do this easily if you are retrieving another attribute

User.where(:nickname.in=>["kk","ll"])

But I am wondering how to do this in mongoid -> this should be a very simple and common operation

  • 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-18T12:51:50+00:00Added an answer on May 18, 2026 at 12:51 pm

    Remember that the ID is stored as :_id and not :id . There is an id helper method, but when you do queries, you should use :_id:

    User.where(:_id.in => arr)
    

    Often I find it useful to get a list of ids to do complex queries, so I do something like:

    user_ids = User.only(:_id).where(:foo => :bar).distinct(:_id)
    Post.where(:user_id.in => user_ids)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of category ids and want to retrieve articles from my
How can i sort (or retrieve sorted array of ) an iphone contact book
I have a PHP array of IDs of rows to retrieve from a MySQL
Let's say I use $.get to receive an array of user IDs. Let us
I have an 'dictionary' array such as this: $arr['a']=5; $arr['b']=9; $arr['as']=56; $arr['gbsdfg']=89; And I
I Have an array of different ids, I want to iterate this array and
using jquery I need to retrieve an array from table cells, format the data
I have a model that I'm trying to retrieve an array of data from,
how do I retrieve the byte array stored in an integer column in my
To retrieve k random numbers from an array of undetermined size we use a

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.