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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:49:36+00:00 2026-06-03T04:49:36+00:00

I have a model with several embedded models. I need to query for a

  • 0

I have a model with several embedded models. I need to query for a record to see if it exists. the issue is that I will have to include reference to multiple embedded documents my query would have to include the following params:

{
 "first_name"=>"Steve",
 "last_name"=>"Grove",
 "email_addresses"=>[
     {"type"=>"other", "value"=>"steve@stevegrove.com", "primary"=>"true"}
 ],
 "phone_numbers"=>[
     {"type"=>"work_fax", "value"=>"(720) 555-0631"},
     {"type"=>"home", "value"=>"(303) 555-1978"}
 ],
 "addresses"=>[
     {"type"=>"work", "street_address"=>"6390 N Main Street", "city"=>"Elbert", "state"=>"CO"}
 ],
}

How can I query for all the embedded docs even though some fields are missing such as _id and associations?

  • 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-03T04:49:37+00:00Added an answer on June 3, 2026 at 4:49 am

    A few things to think about.

    1. Are you sure the query HAS to contain all these parameters? Is there not a subset of this information that uniquely identifies the record? Say (first_name, last_name, and an email_addresses.value). It would be silly to query all the conditions if you could accomplish the same thing in less work.

    2. In Mongoid the where criteria allows you to use straight javascript, so if you know how to write the javascript criteria you could just pass a string of javascript to where.

    3. Else you’re left writing a really awkward where criteria statement, thankfully you can use the dot notation.

    Something like:

    UserProfile.where(first_name: "Steve", 
                       last_name: "Grove", 
                       :email_addresses.matches => {type: "other", 
                                                    value: "steve@stevegrove.com", 
                                                    primary: "true"}, 
                        ..., ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have model helper (used by several different models) called set_guids that sets self.theguid
I have a site that will have several Youtube videos embedded using the standard
I have an object model that contains several lists of other objects. I want
I have a model called City. I have several methods that look for a
I have several Core Data model version that I have added to my .xcdatamodeld
I have a model that has several properties. The properties can be primitive (String)
I have a model class Action that get's extended by several other classes. I
I have a DB model that uses several tables to hold business logic data;
I have a model (and model form based on it) that has several time
I have created a model with several fields that should accept the same data

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.