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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:21:21+00:00 2026-05-28T19:21:21+00:00

I have the structure where A Participant will have embedded many Had_drinks objects.. each

  • 0

I have the structure where

A Participant will have embedded many “Had_drinks” objects.. each “Had_drink” has the possibility (not always) of having a single “Photo” object embedded in it…

I have the ID of a Photo and want to pull out the entire of the photo object. The root of document starts at Participant

Here is a example of the structure.. Below is TWO participants each only have one “had_drink” in this example and the first participant has a photo with theirs

{
    _id: "4f0ecfe57e65260001000002",
    had_drinks: [
        {
        _id: "4f0ed1357e65260001000004",
        at: "2012-01-07T00:00:00-08:00",
        beer_id: "4f0ed1357e65260001000003",
        cost: 3.5,
        location: "Quakers",
        photo: {
            photo_id: "66832993035",
            page_url: "http://www.flickr.com/photos/733355f69@N02/66832993035/",
            square_url: "http://farm8.staticflickr.com/7035/668a3993035_fb180e39648_s.jpg",
            thumbnail_url: "http://farm8.staticflickr.com/7035/6sad683993035_fb65180e9648_t.jpg",
            small_url: "http://farm8.staticflickr.com/7035/66839asd93035_fb1s80e9648_m.jpg",
            medium_url: "http://farm8.staticflickr.com/7035/668s3993035_fb18h0e9648.jpg",
            large_url: "http://farm8.staticflickr.com/7035/66839v93035_fb180e9648_b.jpg",
            original_url: null
            },
        rating: "4",
        uploaded_at: "2012-01-12T04:25:25-08:00"
        }
    ],
    mongoid_user_id: "4f0ecf3e57e65260001000001",
    name: "Michael Mark"
},
{
    _id: "4f08aa477eddd05000100000c",
    had_drinks: [
    {
        _id: "4f0ff0513942d4e000100000b",
        at: "2012-01-07T030:00:00-08:00",
        beer_id: "4f0ff0561394d74e0001000009",
        cost: 4.1,
        location: "Bootleggers",
        photo: null,
        rating: "3",
        uploaded_at: "2012-01-13T030:50:25-08:00"
    }
    ],
    mongoid_user_id: "4f08aa477e34ddd0000100000b",
    name: "Daniel M"
},

How can I achieve getting the photo out?
From what I have learnt in my short time with mongoid and document database I need to start the query from the root and work down?

I was trying something like this

Participant.where(:had_drinks.where(:photo.photo_id => params[:id]))

But think i am miles off so far

—-EDIT 🙂
Thinking it through I guess I need to do the following query

1: Get any Participant With this Photo

2: Select the First Participant

3: Filter their photos to photos with this id

4: Select the first photo (will only actually ever be one)

Just unsure how to do that query in my limited mongoid/mongodb knowledge

  • 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-28T19:21:23+00:00Added an answer on May 28, 2026 at 7:21 pm

    If you have photo id, you can do something like this:

    db.participants.find({'had_drinks.photo.photo_id': '66832993035'}, 
                         {'had_drinks.photo': 1})
    

    That’ll pull all photos from had_drinks array where such photo exists. You have to filter it client-side. AFAIK, there currently is no way to retrieve a single array element (except for map-reduce, of course).

    In ruby this would be something like this:

    participant = Participant.where('had_drinks.photo.photo_id': '66832993035').first
    photo = participant.had_drinks.map{|hd| hd['photo']}. # get only photos
                        compact.  # remove nils
                        select{|p| p['photo_id'] == '66832993035'}. # get only relevant photos
                        first  # and pick first
                        # done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a structure which has 3 main UpdatePanels, each of which has several
I have two tables pertaining to this question: conversations has many messages . The
I have the following structure: List -->List_Participant -->Participant so a list may contain several
I have a structure which I need to populate and write to disk (several
I have a structure in C#: public struct UserInfo { public string str1 {
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a structure: struct pkt_ { double x; double y; double alfa; double
I have a structure that contains an arrays of another structure, it looks something
I have a structure which I create a custom constructor to initialize the members
I have a structure named WaveSize to represent both an amount of samples or

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.