sql >> Database >  >> NoSQL >> MongoDB

selecteer alleen subdocumenten of arrays

Probeerde dit:

db.countries.aggregate(      
    {
        "$project": {
            "state": "$states",
            "_id": 0
        }
    },
    {
        "$unwind": "$state"
    },
    {
        "$group": {
            "_id": "$state.name",
            "state": {
                "$first": "$state"
            }
        }
    },
    {
        "$match": {
            "_id": "orissa"
        }
    }
);

En kreeg:

{
    "result" : [
            {
                    "_id" : "orissa",
                    "state" : {
                            "name" : "orissa",
                            "direction" : "east",
                            "population" : 41947358,
                            "districts" : [
                                    {
                                            "name" : "puri",
                                            "headquarter" : "puri",
                                            "population" : 1498604
                                    },
                                    {
                                            "name" : "khordha",
                                            "headquarter" : "bhubaneswar",
                                            "population" : 1874405
                                    }
                            ]
                    }
            }
    ],
    "ok" : 1


  1. Mongodb collectie objecten totale uren collectie

  2. Inhoudswaarde zoeken in redis door BookSleeve

  3. Hoe kan ik de standaarddatabase van Mongodb in Spring-data wijzigen/definiëren?

  4. Documenten importeren in MongoDB vanuit een array van JSON-documenten