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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:30:41+00:00 2026-06-05T17:30:41+00:00

I have a collection with nested documents in it. Each document also has an

  • 0

I have a collection with nested documents in it. Each document also has an _id field.

Here’s an example of a documents structure

{
   "_id": ObjectId("top_level_doc"),
   "title": "Cadernos",
   "parent": "4fd55bbc5d1709793b000008",
   "criterias": {
     "0": {
       "_id": ObjectId("a_nested_doc"),
       "value": "caderno",
       "operator": "contains",
       "field": "design0" 
    } 
  } 
}

I want to be able to find the nested document just by searching it’s _id

With this query

{
    "criterias._id" : ObjectId("a_nested_doc")
}

It returns the parent document (i just want the one that’s nested).

Ideally I would do this

{
    "_id" : ObjectId("a_nested_doc")
}

And it would return the document with that id (either its nested or not).

Ps. I edited the “_id” values for the sake of simplicity just for this example.

  • 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-05T17:30:42+00:00Added an answer on June 5, 2026 at 5:30 pm

    You may have to live with selecting criterias._id (without writing a wrapper around the query, at least), but you can select the document itself by simply retrieving a subset of the fields.

    http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields

    // The simplest case converted to your use case
    db.collection.find( { criterias._id : ObjectId("a_nested_doc") }, { criterias : 1 } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data structure: One ModelA has a nested collection of ModelBs.
for example I have collection foo of documents like that: {tag_cloud:[{value:games, count:10}, {value:girls, count:500}]}
If I have a document in mongodb with this structure: { _id: user1, loc:
How do I search through mongodb documents where documents have nested documents. For example
I currently have a collection of documents that each contain arrays pointing at other
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I have an object Document with nested Properties (Name, Value) collection. Now I want
I have a schema, with a document structure that looks like this: { _id
I have a method with a nested foreach collection (iterate a set of objects
I have Collection List<Car> . How to compare each item from this collection 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.