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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:30:30+00:00 2026-06-02T22:30:30+00:00

How to search value in multidimensional array, for example I want to search example

  • 0

How to search value in multidimensional array,
for example I want to search example keyword in the following data in mongodb
I used to fetch all data from command

>db.info.find()

{
    "_id" : ObjectId("4f74737cc3a51043d26f4b90"),
    "id" : "12345",
    "info" : [
            {
                    "sno" : 1,
                    "name" : "ABC",
                    "email" : "abc@example.com"
            },
            {
                    "sno" : 2,
                    "name" : "XYZ",
                    "email" : "xyz@example.com"
            },
            {
                    "sno" : 3,
                    "name" : "XYZ",
                    "email" : "xyz@demo.com"
            },
            {
                    "sno" : 4,
                    "name" : "ABC",
                    "email" : "abc@demo.com"
            },
            {
                    "sno" : 5,
                    "name" : "Rohan",
                    "email" : "rohan@example.com"
            }
    ]
}

Now, to find data having example I used command

>db.info.find({"info.email":"example"})
and it gives

{
    "_id" : ObjectId("4f74737cc3a51043d26f4b90"),
    "id" : "12345",
    "info" : [
            {
                    "sno" : 1,
                    "name" : "ABC",
                    "email" : "abc@example.com"
            },
            {
                    "sno" : 2,
                    "name" : "XYZ",
                    "email" : "xyz@example.com"
            },
            {
                    "sno" : 3,
                    "name" : "XYZ",
                    "email" : "xyz@demo.com"
            },
            {
                    "sno" : 4,
                    "name" : "ABC",
                    "email" : "abc@demo.com"
            },
            {
                    "sno" : 5,
                    "name" : "Rohan",
                    "email" : "rohan@example.com"
            }
    ]
}

But I want only 3 out of 5 sub rows like

{
    "_id" : ObjectId("4f74737cc3a51043d26f4b90"),
    "id" : "12345",
    "info" : [
            {
                    "sno" : 1,
                    "name" : "ABC",
                    "email" : "abc@example.com"
            },
            {
                    "sno" : 2,
                    "name" : "XYZ",
                    "email" : "xyz@example.com"
            },
            {
                    "sno" : 5,
                    "name" : "Rohan",
                    "email" : "rohan@example.com"
            }
    ]
}
  • 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-02T22:30:32+00:00Added an answer on June 2, 2026 at 10:30 pm

    I tried Map Reduce Function and it works on this type of problems the code is something like that:

    Write a map function

      map=function () 
      {
          filter = [];
          this.info.forEach(function (s) {if (/example/.test(s.email)) {filter.push(s);}});
          emit(this._id, {info:filter});
      }
    

    Write a reduce function

      reduce=function(key, values) { return values;}
    

    MapReduce Function

      res=db.info.mapReduce(map,reduce,{out:{inline:1}})
    

    And The Output look likes:

    "results" : [
        {
                "_id" : ObjectId("4f9a2de0ea4a65c3ab85a9d3"),
                "value" : {
                        "info" : [
                                {
                                        "sno" : 1,
                                        "name" : "ABC",
                                        "email" : "abc@example.com"
                                },
                                {
                                        "sno" : 2,
                                        "name" : "XYZ",
                                        "email" : "xyz@example.com"
                                },
                                {
                                        "sno" : 5,
                                        "name" : "Rohan",
                                        "email" : "rohan@example.com"
                                }
                        ]
                }
        }
        ],
        "timeMillis" : 1,
        "counts" : {
                "input" : 3,
                "emit" : 3,
                "reduce" : 0,
                "output" : 3
        },
        "ok" : 1,
    

    Now you can find your search data from

       printjson(res.results)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I the following multidimensional array that I want to be able to search a
I used the following code to post a search value via an html button.
I am getting the key from a given value in a multidimensional array. It
I have an array, which I'd like to search for a value in and
I'm trying to add the selected value from the autocomplete search box to my
I have this multidimensional array. I need to search it and return only the
I would like to search key in multidimensional array and i would like to
HTML: I want to pass the value from the gsearch to the q parameter.
I have a multidimensional array. I need to search it for a specific range
I am attempting to use a recursive function to search through a multidimensional array,

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.