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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:24:20+00:00 2026-05-24T01:24:20+00:00

The solution is probably staring me in the face, but I haven’t had any

  • 0

The solution is probably staring me in the face, but I haven’t had any luck in finding it. My problem is that I need to find all documents which contain specified DBRef. Here’s the structure of the collection to be searched:

{
    "_id" : ObjectId("4e2d4892580fd602eb000003"),
    "date_added" : ISODate("2011-07-25T11:42:26.395Z"),
    "date_updated" : ISODate("2011-07-25T11:43:09.870Z"),
    ...
    "a_list_of_dbrefs" : [
        {
            "$ref" : "somecollection"
            "$id" : "4e2d48ab580fd602eb000004"
        }
    ],
    ...
    "name" : "some name"
}

I need to be able to retrieve a set of documents based on a DBRef appearing in a_list_of_dbrefs (some a_list_of_dbrefs may contain no DBRefs, others may contain 1, and others may contain more than 1).

How is this accomplished?

  • 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-24T01:24:21+00:00Added an answer on May 24, 2026 at 1:24 am

    I’d recommend dumping the DBRefs in favor of simply storing the _id of the referenced document assuming you know the name of the collection being referenced.

    There is absolutely no way to “resolve” an array of DBRef from the server-side (in a single step) on MongoDB and requires that you loop through the array on the client and individually resolve each document.

    Conversely, if you store an array of just the referenced _id you can retrieve that array and then use the $in query to fetch them all.

    So your document might change to look like this:

    {
        "_id" : ObjectId("4e2d4892580fd602eb000003"),
        "date_added" : ISODate("2011-07-25T11:42:26.395Z"),
        "date_updated" : ISODate("2011-07-25T11:43:09.870Z"),
        ...
        "references": [
            ObjectId(123), ObjectId(234), ObjectId(567), ObjectId(891)
        ],
        ...
        "name" : "some name"
    }
    

    You can then query MongoDB using the contents of the references field:

    db.somecollection.find({"_id": {"$in": references}})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched a lot but couldn't find any solution. I am probably using the
This is probably easily figured out, but I can't find a solution anywhere, for
This is probably a simple question but I can't seem to find the solution.
This is probably basic, but I can't find a solution. I have a string,
I have a strange problem that probably has a simple solution that I just
Is a simple exercice, probably some solution better than others, but I wonder which
This is probably an easy solution but I can't get my head around it.
This is blowing my mind because it's probably an easy solution, but I can't
this is probably a useless problem but it stuck on my mind for few
This is probably not secure but ignore that. Ive made a simple homepage with

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.