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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:27:20+00:00 2026-05-15T23:27:20+00:00

This example makes it seem like both are used ( include d) in order

  • 0

This example makes it seem like both are used (included) in order to make a class a persistent model, but it is not clear when I should use one or the other.

  • 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-15T23:27:20+00:00Added an answer on May 15, 2026 at 11:27 pm

    A MongoMapper::Document is saved to the database as a top-level record. A MongoMapper::EmbeddedDocument is saved within another document. For instance, let’s say I have a blogging application. I have a Post and Comment model. They might look something like this:

    require 'mongo_mapper'
    MongoMapper.database = 'test'
    
    class Post
      include MongoMapper::Document
    
      key :title
      key :body
      key :comments
    
      many :comments
    end
    
    class Comment
      include MongoMapper::EmbeddedDocument
    
      key :author
      key :body
    end
    
    p = Post.new(:title => 'Some post', :body => 'About something')
    p.comments << Comment.new(:author => 'Emily', :body => 'A comment')
    
    p.save
    
    puts Post.all.map(&:inspect)
    

    Will produce a document in your mongo database that looks like this:

    { "_id" : ObjectId("4c4dcf4b712337464e000001"),
      "title" : "Some post",
      "body" : "About something",
      "comments" : [
            {
                    "body" : "A comment",
                    "author" : "Emily",
                    "_id" : ObjectId("4c4dcf4b712337464e000002")
            }
    ] }
    

    In terms of interacting with them through MongoMapper, only a MongoMapper::Document response to methods like find and save. A MongoMapper::EmbeddedDocument can only be accessed through its parent document. The implication of this is that you should only use MongoMapper::EmbeddedDocument for models that are clearly subsidiary to their parent models and will only be used in the context of that parent.

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

Sidebar

Related Questions

hello i am make like this example which i get from www.xxxxxx.com http://s1172.photobucket.com/albums/r568/novikoraharja/?action=view&current=justanimage.png i
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
This may seem strange... but I'm wondering if there is anyway to make a
In this example, the Google App Engine documentation makes the Customer the entity group
How can i make multiple, composite query in oracle? for example this several queries
How can I make this sliding panel example to slide down on mouseover and
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
How do I make awk recognise character classes? For example, this: echo a\n1\nb\n2\nc |
Code snippet to follow. I have a struct (example code has class, tried both,

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.