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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:05:03+00:00 2026-06-07T15:05:03+00:00

I have an embedded document within a Mongodb document. The Mongodb document looks like

  • 0

I have an embedded document within a Mongodb document. The Mongodb document looks like this:

[_id] => home
[url] => /
[type] => homepage
[people] => Array (
    [0] => Array (
        [name] => John Smith
        [rewrite] => john-smith
    )
    [1] => Array (
        [name] => John Q. Public
        [rewrite] => john-q-public
    )
)

I’m trying to iterate over the people embedded document. In my app.rb, I’m passing the object to haml like this:

DB = Mongo::Connection.new.db("website", :pool_size => 5, :timeout => 5)                                                              
pages = DB.collection('pages')                                                                                                      

get '/' do                                                                                                                          
  home = pages.find_one( :type => "homepage" )                                                                                                                                                                     
  haml :index, :attr_wrapper => '"', :locals => {:items => home}                            
end                                                                                                                                 

In my index.haml, I’m can iterate over the entire document like so:

-items.each do |item|
  %h2= item

But how can I just iterate over the people embedded document? I’d like to do something like this:

-items.people.each do |person|
  %h2= person.name, person.rewrite

Also, please correct me if I’m using improper terminology; I’m new to Mongo, Haml, Sinatra, etc.

  • 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-07T15:05:07+00:00Added an answer on June 7, 2026 at 3:05 pm

    Maybe I should learn Ruby syntax a bit more… Here’s how I was able iterate into my people embedded document:

    -items["people"].each do |person|
      %h2= person["name"], person["rewrite"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document layout like this: Program = { '_id':ObjectId('4321...'), 'Title':'The Title', 'Episodes':[
I have embedded the fullcalendar jquery control by using this code: $(document).ready(function() { var
i have an embedded document within a document as following : { user:Alex, actions:
I have a model like this: class Search include Mongoid::Document embeds_many :terms accepts_nested_attributes_for :terms
I have a CSV string that is embedded within an XML document, which is
Currently I have an address column that is an embedded document in my users
So I have an embedded document that tracks group memberships. Each embedded document has
I have a document with an embedded document in it. I have 2 forms,
I have products as an embedded document inside the category class as shown below:
I have a problem with relationships persisting in an embedded document. Here is the

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.