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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:05:13+00:00 2026-06-01T19:05:13+00:00

Hi I have embedded documents but i can’t query them by id. I can

  • 0

Hi I have embedded documents but i can’t query them by id. I can output all with inspect and there are the right ids but querying them is not possible.
I have a Course Model which embeds_many :course_members and a CourseMember Model with embedded_in :course, :inverse_of => :course_members

I tried this without any success:

puts Course.where("course_members.id" => params[:id])

With this code i can reach the rigth document:

c = Course.where("course_members.accepted" => 2).all
c.each do |l|
 l.course_members.each do |f|
  puts f.inspect
 end
end

But how can i get my data with one Mongoid query?

  • 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-06-01T19:05:15+00:00Added an answer on June 1, 2026 at 7:05 pm

    I guess

    puts Course.where("course_members._id" => BSON::ObjectId(params[:id]))
    

    The real id argument in MongoDB is _id, the function .id in mongoid is just a convenient wrapper.

    Edit: You also have to convert your string params[:id] to a correct BSON ID.

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

Sidebar

Related Questions

assume that i have a BlogPost model with zero-to-many embedded Comment documents. can i
I need to get pointed in the right direction. I have embedded an Iron
I have an embedded PowerPoint presentation in an Excel workbook. How can I edit
I've embedded a LinkedIn Apply Now button on my page . But there are
Can someone point me in the right direction, i have a Collection (Forms) each
Currently I have an address column that is an embedded document in my users
I have a link in a pdf-document (PDF1), which is embedded in a browser
I have embedded a Python interpreter in a C program. Suppose the C program
I have embedded a JTextArea on a JScrollPane and am using that JTextArea for
I have embedded an IronPython engine in a C# application. I want to expose

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.