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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:05:27+00:00 2026-05-14T20:05:27+00:00

I am currently trying to learn Ruby On Rails as I am a long-time

  • 0

I am currently trying to learn Ruby On Rails as I am a long-time PHP developer so I am building my own community like page.

I have came pretty far and have made the user models and such using MySQL.

But then I heard of MongoDB and looked in to it a little bit more and I find it kind of nice.

So I have set it up and I am using mongomapper for the connection between rails and MongoDB.

I’m now using it for the News page on the site.

I also have a profile page for every User which includes their own guestbook so other users can come to their profile and write a little message to them.

My thought now is to change the User models from using MySQL to start using MongoDB.

I can start by showing how the models for each User is set up.

The user model:

class User < ActiveRecord::Base
            has_one :guestbook, :class_name => "User::Guestbook"

The Guestbook model model:

class User::Guestbook < ActiveRecord::Base
  belongs_to :user
  has_many :posts, :class_name => "User::Guestbook::Posts", :foreign_key => "user_id"

And then the Guestbook posts model:

class User::Guestbook::Posts < ActiveRecord::Base
  belongs_to :guestbook, :class_name => "User::Guestbook"

I have divided it like this for my own convenience but now when i am going to try to migrate to MongoDB i dont know how to make the tables.

I would like to have one table for each user and in that table a “column” for all the guestbook entries since MongoDB can have a EmbeddedDocument. I would like to do this so i just have one Table for each user and not like now when i have three tables just to be able to have a guestbook.

So my thought is to have it like this:

The user model:

class User
  include MongoMapper::Document
  one :guestbook, :class_name => "User::Guestbook"

The Guestbook model model:

class User::Guestbook
  include MongoMapper::EmbeddedDocument
  belongs_to :user
  many :posts, :class_name => "User::Guestbook::Posts", :foreign_key => "user_id"

And then the Guestbook posts model:

class User::Guestbook::Posts
  include MongoMapper::EmbeddedDocument
  belongs_to :guestbook, :class_name => "User::Guestbook"

But then i can think of one problem.. That when i just want to fetch the user information like a nickname and a birthdate then it will have to fetch all the users guestbook posts. And if each user has like a thousand posts in the guestbook it will get really much to fetch for the system. Or am I wrong?

Do you think I should do it any other way?

  • 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-14T20:05:27+00:00Added an answer on May 14, 2026 at 8:05 pm

    No you don’t have to fetch all the guestbook entries if you fetch a user, this is the mongo query for and MongoMapper shouldn’t work so much differently (For myself, I’m using Mongoid):

    db.users.find({_id: '21314'}, {guestbook: 0})
                    // instead of {guestbook: 1} which would return only the guestbook
    

    Something to be aware of, MongoDB still has a limit of 4mb for a single document but that should be tens of thousands of guestbook entries. You might as well push older ones into a sort of archive.

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

Sidebar

Related Questions

I've recently installed Ruby on Rails 3.2 and have been trying to learn it.
I'm currently reading Beginning Rails 3. I'm coming from PHP and trying to learn
I'm currently trying to learn Rails, and in the process, I compiled Ruby on
I'm currently trying to learn ACSL, a precompiled language for Fortran, and have found
I am currently trying to learn Android. Have been reading tutorials and manual for
I am currently trying to learn how to use easymock. I have the following
I am trying to learn rails from http://ruby.railstutorial.org/ Exercise 3 explains to install rspec,
I'm currently trying to learn some Prolog (using ECLiPSe). From time to time I
I'm trying to learn ruby on rails. I've been going through a tutorial, but
I'm trying to learn both Ruby and Rails and I'm looking at Michael Hartl's

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.