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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:41:16+00:00 2026-06-03T00:41:16+00:00

Consider the following Mongoid Model class Doc include Mongoid::Document field :name, type: String embeds_many

  • 0

Consider the following Mongoid Model

class Doc
  include Mongoid::Document
  field :name, type: String
  embeds_many :images
  embeds_many :videos
end

class Image
  include Mongoid::Document
  field :url, type: String
  field :caption, type: String
  embedded_in :Doc
end

class Video
  include Mongoid::Document
  field :url, type: String
  field :caption, type: String
  embedded_in :Doc
end

versus this model

class Doc
  include Mongoid::Document
  field :name, type: String
  embeds_many :images
  embeds_many :videos
end

class Image
  include Mongoid::Document
  embeds_many :urls
  embeds_many :captions
  embedded_in :Doc
end

class Video
  include Mongoid::Document
  embeds_many :urls
  embeds_many :captions
  embedded_in :Doc
end

class Url
  include Mongoid::Document
  embedded_in :image
  embedded_in :video
  field :url, type: String
end

class Caption
  include Mongoid::Document
  embedded_in :image
  embedded_in :video
  field :caption, type: String
end

What the benefit of each model over the other?

Should I go for the first one for it’s brevity, or should I atomize it to the url.url point so that I have more control for queries later?

  • 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-03T00:41:17+00:00Added an answer on June 3, 2026 at 12:41 am

    The first model allows you to associate exactly one URL with each image or video. The second model allows you to associate many URLs with each image or video.

    Which is a better fit for your business requirements? Is it possible for an image to have many URLs or is there only one?

    Personally, I’d go with the first model unless you strictly need many URLs for a given image. Since the URL of each piece of media on the web is pretty much guaranteed to be unique, there’s really no point in over-normalizing the data structure. You’ll have just as many records in the URL class as the combined total of Video and Image records, so what would you save?

    If it was some other string field that could have non-unique values (say Tags, for example) then it makes great sense to break it out since you’ll have dramatically fewer records in the Tags model then the Image and Video records, assuming a high degree or tag re-use.

    Make sense?

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

Sidebar

Related Questions

Consider the following: class Parent include Mongoid::Document field:name references_one :child before_create :initialize_child protected def
Consider following code public class City { public string Name { get { return
Consider following simple example: Area.hh #pragma once class Area; #include <QScrollArea> class Area :
Consider following schema: Customers: Col | Type | -------------------| id | INTEGER | name
Please consider following sample table structure: +-------------------------------+--------------+------+-----+---------+-------+ | Field | Type | Null |
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider following code: main.cpp: #include <iostream> typedef void ( * fncptr)(void); extern void externalfunc(void);
Consider following XML document fragment: <Book> <Title>Example</Title> <Content> Some line </Content> <TOC> Again some

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.