Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how to find the matched record in mongodb


how to find the matched record in mongodb  using -'java,mongodb,find'

I have a record in my collection and I want to fetch the details of the person whose id is 1. But I am getting the details for 2times instead of 1.

    db.mycollection.insert({"person" : [ { "id":1, "details" : { "name" : "Aswini", "Age" : 10 }}, { "id":2, "details" : { "name" : "Mahesh", "Age" : 11}}]})


Then running

    > db.mycollection.findOne({"person.id":1},{"person.details":1,"_id":0})


the result is :

    {
        "person" :
                [
                    {
                        "details" :
                        {
                         "name" : "Aswini",
                         "Age" : 10
                        }
                    },
                    {
                        "details" :
                        {
                         "name" : "Mahesh",
                         "Age" : 11
                        }
                    }
                ]
    }


But I need as follows:

    {
    "person" : [
                {
                "details" : {
                            "name" : "Aswini",
                            "Age" : 10
                        }
                }
            ]
    }


Don't understand where am making mistake. Please need your help. Am using MongoDB, Java
    

asked Oct 6, 2015 by abhi
0 votes
4 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...