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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:26:57+00:00 2026-06-10T05:26:57+00:00

I’m trying to figure out how to link/reference a document to another document but

  • 0

I’m trying to figure out how to link/reference a document to another document but I’m not finding much information or examples in the docs or other sources. When linking documents, do I have to link by ObjectID or can I use any field? Do I need to pull the field value directly from the originating document or can I pass the same value from anywhere? For example, given a hex string of a UUID object, I want to link 2 documents via a field ‘GUID’ which contains the uuid1 object:

 # What is more efficience/the correct way, option 1 or 2?

 # Option 1
 hexString = '5d78ad35ea5f11e1a183705681b29c47'
 newLinkField = { 'linkToSong' : uuid.UUID( hexString ) }
 db.artists.update( { 'name' : 'Bob Dylan' }, { $set : newLinkField }, upsert = False)

 # Option 2
 hexString = '5d78ad35ea5f11e1a183705681b29c47'
 songGUID = db.songs.find_one({ 'GUID' : uuid.UUID( hexString ) }, {'GUID': 1 });
 newLinkField = { 'linkToSong' : songGUID }
 db.artists.update( { 'name' : 'Bob Dylan' }, { $set : newLinkField }, upsert = False)

Also, is this storing actual links or just duplicates of the UUID object?

  • 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-10T05:26:58+00:00Added an answer on June 10, 2026 at 5:26 am

    I highly recommend this 10gen video for understanding linking and embedding, how to use them, and what the tradeoffs are:

    http://www.10gen.com/presentations/mongosv-2011/schema-design-principles-and-practice

    To answer your questions: “linking” a document A to a document B simply means putting some information in A that allows your application to query for B. Typically, it’d be something like this:

    // Document A, in collection 'comments':
    { _id: ObjectId('123...'), user: ObjectId('abc...'), text: 'Hi!' }
    
    // Document B, in collection 'users':
    { _id: ObjectId('abc...'), name: 'Jesse' }
    

    Document A, my comment, is linked to B, my user profile. Your application can query for A however it wants to (by _id, by user, by text, …) and then examine its ‘user’ field, then find my user profile by querying the users collection for that ObjectId.

    The field you use to link A to B should probably be unique in B’s collection, and it should definitely be indexed in B’s collection.

    Both requirements are always satisfied by any collection’s _id field, but they could be satisfied by some other field as well.

    Your example 1 is fine. Although you probably have it backwards: songs should have artist ids in them, rather than vice-versa, unless Bob Dylan has only ever written one song.

    In example 2, it is unnecessary and costly to find the song before the artist, if you already know how you’re going to query for the artist document.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.