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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:19:18+00:00 2026-05-28T20:19:18+00:00

I have have a collection called users . Each user document has an embedded

  • 0

I have have a collection called users. Each user document has an embedded document called phone numbers.

}
   "_id": ObjectId("4f2984b1af06e80418000000"),
   "User_FirstName": "Frank",
   "User_LastName": "Williams",
   "User_PhoneNumbers": [
                  {"Phone_Type": "Home","Phone_Number: "555-555-5555" },
                  {"Phone_Type": "Mobile","Phone_Number: "333-333-3333" }
                  ]
}

I am trying to display all the phone numbers for the user named “Frank Williams”. I would like to use a loop that returns the results (all phone numbers for a particular user):

Home, 555-555-5555
Mobile, 333-333-33333

I am new to mongodb and don’t know how to query an embedded document and have it return all the embedded documents for that particular user. I am coding in php. Thank you for any help.

  • 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-28T20:19:19+00:00Added an answer on May 28, 2026 at 8:19 pm

    At best you can return only the whole User_PhoneNumbers array. You cannot pick individual items out of it. (I am talking about regular queries, of course. With map-reduce or upcoming Aggregation Framework you’ll be able to do this).

    db.collection.find({"_id": ObjectId("4f2984b1af06e80418000000")}, 
                       {"User_PhoneNumbers": 1, _id: -1});
    

    This query will return this document:

    {
       "User_PhoneNumbers": [
                  {"Phone_Type": "Home","Phone_Number": "555-555-5555" },
                  {"Phone_Type": "Mobile","Phone_Number": "333-333-3333" }
                ]
    }
    

    Then in PHP you can handle it however you want.

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

Sidebar

Related Questions

I have three entities: User , Team , and TeamInvite . Each User has
We have installed TFS 2010 RC. By default it creates a project collection called
I have a collection of an object called Bookmarks which is made up of
I have Collection List<Car> . How to compare each item from this collection with
I'm planning to have collection of items stored in a TCollection. Each item will
I have a model called Metadatum (silly, I know) which has two fields, key
I have a model called UserPrice and I want to let users be able
Assume I have a user defined Java class called Foo such as: public class
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
I have a collection of objects to which I'd like to just add a

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.