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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:18:43+00:00 2026-06-03T13:18:43+00:00

Suppose the following model : class Product include MongoMapper::Document key :name, String key :product_category_id,

  • 0

Suppose the following model :

class Product 
 include MongoMapper::Document

 key :name, String
 key :product_category_id, ObjectId

 belongs_to :product_category
end

class ProductCategory
 include MongoMapper::Document

 key :name, String, :required => true, :unique => true

 timestamps!
 userstamps!
end

I want to implement an advanced search that will inspect all value inside my Model including its all association like :
I have :

  • Product A data named “aLaptop” belongs_to:ProductCategory named “Notebook”.
  • Product B data named “aGreatNotebook” belongs_to:ProductCategory named “Notebook”.

When I search with keyword named “Notebook”, I want to search it to Product.name fields and also its associations which mean ProductCategory.name also. So it will returned both of that items, because Product A have ProductCategory.name “Notebook” & Product B have Product.name “aGreatNotebook” and ProductCategory “Notebook”..

How can I do this?? I’ve already searching for 2 days and not success until now:(.. When is in MySQL, I used join table.. But hows in MongoMapper??

Please help.. Thank you..

  • 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-03T13:18:44+00:00Added an answer on June 3, 2026 at 1:18 pm

    You can’t do joins in MongoDB. So the basic idea is to get the ObjectId associated with the “Notebook” category and then to query the products where product_category is equal to notebook_id. This generally involves two queries. So that’d be something like this:

    notebook_id = ProductCategory.first(:name => "Notebook")
    if notebook_id
      Product.where({:product_category_id => notebook_id['_id']})
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose the following model. class Person include MongoMapper::Document key :name, String key :surname, String
Suppose the following model public class Product { private Integer requiredQuantity; private Integer allowedQuantity;
suppose the following simple models: class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() class
Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Suppose I have the following Event model: from django.db import models import datetime class
suppose we have a model in django defined as follows: class Literal: name =
The scenario Suppose I have the following two model classes: public class ProductColor {
I have the following model: class A(models.Model): name = models.CharField(max_length=50) content_type = models.ForeignKey(ContentType) This
Suppose that I have the following HBM mapping: <class name=Student table=student> <set name=classes table=student_classes
Suppose the following object structure: class Super {} class SubA extends Super {} class

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.