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

  • Home
  • SEARCH
  • 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 6786665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:16:23+00:00 2026-05-26T17:16:23+00:00

I am trying to retrieve all cards from Mongoid that have request=preview I’m doing

  • 0

I am trying to retrieve all “cards” from Mongoid that have request=”preview”

I’m doing this via:

  @preview_cards = Card.where("request" => "PREVIEW")

I have a few questions.

1) Why can’t I do?

  @preview_cards = Card.find_by_request("PREVIEW")

I get an error: undefined method `find_by_request’ for Card:Class

2) Once I have the cards in the @preview_cards variable, I can’t iterate through them. For example:

@preview_cards.each do |c| c.fullname end

simply just returns the object id #<Mongoid::Criteria:0x103eaf778>

3) Is there an “all” method you can call instead of first and last. For example, this works:

@preview_cards.first.fullname

but i want to be able to iterate through each “row” in mongo.

Any help would be greatly appreciated! Thanks.

  • 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-26T17:16:23+00:00Added an answer on May 26, 2026 at 5:16 pm

    No schema, so no automagic method generation. You can create your own helpers, though.

    Are you sure? That works fine for me. What’s returned is different than what happens once you try iterating. For example:

    [19] pry(main)> ts = FooDoc.where("name" => "ohai")
    => #<Mongoid::Criteria
      selector: {"name"=>"ohai"},
      options:  {},
      class:    FooDoc,
      embedded: false>
    
    [20] pry(main)> ts.each { |t| p t.name }
    "ohai"
    => #<Mongoid::Criteria
      selector: {"name"=>"ohai"},
      options:  {},
      class:    FooDoc,
      embedded: false>
    

    For getting all, use all:

    Card.all(conditions: { request: "PREVIEW" })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying to retrieve all private methods in my class that have
I'm trying to retrieve files from sharepoint via SSRS and an XML Datasource. This
I'm trying to build a script to retrieve all feed entries from a given
I'm trying to retrieve all the addresses from the address book and display them
I'm trying to retrieve all the users ids who have their preferences (IN (1,7)
I am trying to retrieve all the certificates from windows-MY, but some of them
I'm trying to retrieve all the data id from a database where their tags(array)
I am trying to retrieve all the files in all the folders I have
i need help with php code trying to retrieve all information from a table
I'm trying to retrieve all of the keys from a DynamoDB table in an

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.