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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:24:50+00:00 2026-06-14T09:24:50+00:00

Looking for a little guidance in setting up a MongoDB schema. Here’s the scenario:

  • 0

Looking for a little guidance in setting up a MongoDB schema. Here’s the scenario:

I’m creating a save bookmark feature for people. In the DB, all I need to store is the username, a title, and a link. From this, I would need to create a service that outputs JSON and queries a particular bookmark or a person’s entire feed. Which of the two set ups makes more sense from both an implementation and performance stand point?

A) Each bookmark is its own object:

{
    "_id":  ObjectId("abcd1234"),
    "username": "Choy",
    "title": "This is my first link",
    "url":  "http://www.google.com" 
},
{
    "_id":  ObjectId("abcd1234"),
    "username": "Choy",
    "title": "This is my second link",
    "url": "http://www.bing.com"
}

B) Each user is its own object:

{
    "_id": "Choy",
    "bookmarks": {
        "abcd1234": {
            "title": "This is my first link",
            "url": "http://www.google.com"
        },
        "abcd12345": {
            "title": "This is my second link",
            "url": "http://www.bing.com"
        }
    }
}

Initially (A) made more sense to me, as I could easily query a specific bookmark, update, and remove it. But from the application point of view, (B) would be easier when I want to list all the bookmarks for a person as I could just do a findOne(username) on the _id instead of having to iterate through each record after doing a find(username) and convert to an array and then JSON (which I believe is a bit memory intensive).

On the other hand, it would be an extra step in (B) to add a new bookmark, as I would have to get the record, push a new bookmark into it and then save.

  • 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-14T09:24:51+00:00Added an answer on June 14, 2026 at 9:24 am

    When you have a has-a relation in MongoDB, it is usually the best decision to embed the data in the object which owns it.

    Your goal is to fulfill the needs of the user with as few searches as possible, because every single document lookup costs time. When you don’t need all the bookmarks from a user but only specific ones, you can always use the dot notation to reach into objects and retrieve subsets of fields.

    Aggregation instead of relation is also useful when you delete or rename a user. MongoDB can’t do auto-cascade like SQL databases, so you have to deal with any orphaned data yourself in that case. But when the user document is self-contained, this won’t be a problem.

    So I would recommend you to go for solution B).

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

Sidebar

Related Questions

I'm just looking for a little guidance as to how i might implement a
I have a little / weird behaviour here and Im looking over internet and
I'm looking into a possible feature for my little to-do application... I like the
I am looking for a little bit of guidance today with the issue I
I'm looking for some guidance on the overall architecture of this little system I'm
I'm looking for some guidance here. On my site I put things in Web
Ok, new coder here looking for a little insight into this problem. So I
New to jQuery/javascript here and looking for a little help. I am writing a
I'm looking for a little help structuring a web form to include PHP validation
I have heard conflicting stories on this topic and am looking for a little

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.