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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:05:09+00:00 2026-05-29T10:05:09+00:00

Given the example doc below: { _id : 2, objects : [{ _id :

  • 0

Given the example doc below:

{
  "_id" : "2",
  "objects" : [{
      "_id" : "1",
      "name" : "embedded "
    },{
      "_id" : "2",
      "name" : "embedded "
    },{
      "_id" : "3",
      "name" : "embedded "
    }],
  "name" : "gloss2"
}

Is it possible to return only one subdocument? That way I don’t have to select the whole parent object, get the list, and loop through the list to get the object in question.

{
    "_id" : "2",
    "name" : "embedded"
}
  • 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-29T10:05:11+00:00Added an answer on May 29, 2026 at 10:05 am

    Is it possible to return only one subdocument?

    Yes, but not the way you want. If you do the following, you will only get back the first element of the array:

    coll.find({_id:'2'}, { 'objects.0': 1})
    

    However, what you really want is something that looks like the following:

    coll.find({_id:'2', 'objects._id': '3'}, { 'objects.$' : 1})
    

    Of course, that does not actually work in MongoDB.

    Looking at your other question, this is one of the reasons to use the “embedded object” instead of the “array of objects”. With “embedded object” you could do the following:

    coll.find({_id:'2'}, {'objects.3': 1}) // where 3 is the id of the third object
    

    This lets you pick just the “embedded objects” you need.

    That way I don’t have to select the whole parent object…

    The thing with MongoDB is that the parent document is always fetched. Queries return top-level documents. This is baked into the whole architecture. Even if you request just a slice of the document the server still has to load the entire document into memory before serving you the requested piece.

    The only way around this may be the new Aggregation Framework, but that is not yet in the stable branch.

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

Sidebar

Related Questions

Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given the example source code below, is it possible for someone to see the
Given the example below, can someone please show me how this could be called?
Given this example, how would I return the result of the equation rather than
Given the following XML file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema> <sequence>
This is copied ditto from example given in Sql2008 R2 doc - Syntax: DATENAME
In the example given below, I was expecting the line $a=b in the todel.txt
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Given an example of calling two web services methods from a session bean, what

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.