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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:22:33+00:00 2026-05-31T15:22:33+00:00

I have a model like this: class Lesson include Mongoid::Document field :title, :type =>

  • 0

I have a model like this:

class Lesson
  include Mongoid::Document

  field :title, :type => String
  field :category, :type => String
  field :price, :type => Float
  field :description, :type => String
  field :user_id, :type => String


  validates_presence_of :title
  validates_presence_of :category
  validates_presence_of :price
  validates_presence_of :user_id

  attr_accessible :title, :category, :description, :price

end

And I am trying to query like this:

@lessons_by_user = Lesson.find_by_user_id current_user.id

And I am getting:

undefined method `find_by_user_id’ for Lesson:Class

How can I query by a specific attribute in MongoID?

I know how to do it like this:

@lessons = Lesson.all(:conditions=>{:user_id=>current_user.id.to_s}) 

but I am wondering if there is a shortcut…

  • 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-31T15:22:35+00:00Added an answer on May 31, 2026 at 3:22 pm

    Mongoid doesn’t have the ActiveRecord style auto-created finder methods, it only supports a limited set of predefined finder methods:

    • Model.all
    • Model.count
    • Model.exists?
    • Model.find
    • Model.find_or_create_by
    • Model.find_or_initialize_by
    • Model.first
    • Model.last

    However, it does have a general purpose where method so you say this:

    @lessons = Lesson.where(:user_id => current_user.id)
    

    where is chainable as well (just like where in newer versions of ActiveRecord) so you can add more conditions or specify the ordering by chaining more criteria calls.

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

Sidebar

Related Questions

I have a model like this class Canvas include Mongoid::Document field :name referenced_in :hero
I have a model like this: class Search include Mongoid::Document embeds_many :terms accepts_nested_attributes_for :terms
I have an object model like this: class Car { public string Manufacturer; public
I want to have a django model like this: class Model(models.Model): string = models.CharField()
I have a model like this: public class Instrument { public string Id {
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
I have model that looks like this: public class Lesson { public int Id
I have a model class like this: class Person { string FirstName, string LastName,
I have a model that looks like this: class Movie(models.Model): title = models.CharField(max_length=200) slug
I have a basic Core data model like this: Class -Class Name (string) Relationship:

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.