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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:37:17+00:00 2026-06-05T08:37:17+00:00

Please tell me what am I missing here: this is the Doc I created:

  • 0

Please tell me what am I missing here:

this is the Doc I created:

 fatDoc = {
 name: "Babak",
 personID : 555,
 email : "babak@babak.name",
 music : ["pink floyd", "muse", "garfunkel"],
 food : ["free food", "yummy food", "mom food"],
 addresses:
   [ { type: "home",
       street: "123 Main",
       state: "NY",
       city: "brooklyn"
    },
    { type: "vacation",
      street: "456 sunshine",
      state: "CA",
      city: "SanFran"
    }
  ]   
 }

and this is the query I run on it:

db.coolkids.find({"addresses.type" : "home"}, {addresses:1}).pretty()

Question1: Why BOTH of addresses are getting returned as the result of this query?
Question2: How can I change it to ONLY return the first doc which is the “home” address and not the second member of the array?

  • 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-05T08:37:19+00:00Added an answer on June 5, 2026 at 8:37 am
    1. your query matches this document, and you are getting back the field “addresses” which happens to be an array. In 2.0 the only way to get back less than the full array is via $slice operator but you would need to know the position of the element you want.

    2. The way to get back just one element that matches your query would be using the new Aggregation Framework (available in development version 2.1, will be released with 2.2).

    Aggregation Framework will allow you to “$unwind” arrays so that you can get back just the document with array element that matched your filter.

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

Sidebar

Related Questions

Can somebody please tell me what I am missing in this formula in SSRS?
Please tell me I'm missing something obvious here. I am getting a syntax error
I'm not sure if this question is non-sense or not, please tell me if
Please can someone really tell me what's wrong with this code that I'm having
I cannot get this crazy dependency to work and please don't tell me to
Please tell me how I can hide textarea in td table, what attribute must
Please tell me what is the Qt equivalent function for glutswapbuffers()..
Please tell me why my window doesn't render. Below is the javascript that i
Please tell me if it is possible to do the following: create an instance
Please tell me what will the call to given function return and how? The

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.