Mongodb поиск и фильтрация во вложенном массиве данных - PullRequest
0 голосов
/ 21 декабря 2018

Я хочу отфильтровать массив и получить все результаты при запросе

[{
    "college_id" : 25,
    "name" : "IIT",
    "city" : "Delhi",
    "courses" : [ 
        {
            "discipline_name" : "engineering",
            "course_list" : [ 
                {
                    "course_type" : "Bachelor of Technology [B.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "48"
                        }, 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Electrical Engineering)",
                            "fees" : 20000,
                            "duration" : "48"
                        }
                    ]
                },
                {
                    "course_type" : "Master of Technology [M.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Master of Technology [M.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "24"
                        }, 
                        {
                            "program_name" : "Master of Technology [M.Tech] (Electrical Engineering)",
                            "fees" : 20000,
                            "duration" : "24"
                        }
                    ]
                }
            ]
        }
    ]
},
{
    "college_id" : 75,
    "name" : "NIT",
    "city" : "Kolkata",
    "courses" : [ 
        {
            "discipline_name" : "engineering",
            "course_list" : [ 
                {
                    "course_type" : "Bachelor of Technology [B.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "48"
                        }, 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Electrical Engineering)",
                            "fees" : 20000,
                            "duration" : "48"
                        }
                    ]
                }
            ]
        },
        {
            "discipline_name" : "management",
            "course_list" : [ 
                {
                    "course_type" : "Master in Business Administration [MBA]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Master in Business Administration [MBA] (Finance)",
                            "fees" : 40000,
                            "duration" : "48"
                        }, 
                        {
                            "program_name" : "Master in Business Administration [MBA] (Marketing)",
                            "fees" : 20000,
                            "duration" : "48"
                        }
                    ]
                }
            ]
        }
    ]
}]

Вопросы: 1. Найдите, где сборы больше 30000. Выходные данные должны быть:

[{
    "college_id" : 25,
    "name" : "IIT",
    "city" : "Delhi",
    "courses" : [ 
        {
            "discipline_name" : "engineering",
            "course_list" : [ 
                {
                    "course_type" : "Bachelor of Technology [B.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "48"
                        }
                    ]
                },
                {
                    "course_type" : "Master of Technology [M.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Master of Technology [M.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "24"
                        }
                    ]
                }
            ]
        }
    ]
},
{
    "college_id" : 75,
    "name" : "NIT",
    "city" : "Kolkata",
    "courses" : [ 
        {
            "discipline_name" : "engineering",
            "course_list" : [ 
                {
                    "course_type" : "Bachelor of Technology [B.Tech]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Bachelor of Technology [B.Tech] (Biotechnology)",
                            "fees" : 40000,
                            "duration" : "48"
                        }
                    ]
                }
            ]
        },
        {
            "discipline_name" : "management",
            "course_list" : [ 
                {
                    "course_type" : "Master in Business Administration [MBA]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Master in Business Administration [MBA] (Finance)",
                            "fees" : 40000,
                            "duration" : "48"
                        }
                    ]
                }
            ]
        }
    ]
}]

2.Найдите, где плата больше 30000 и меньше 50000, а «course_type» - это «Мастер делового администрирования [MBA]» Пример вывода

[{
    "college_id" : 75,
    "name" : "NIT",
    "city" : "Kolkata",
    "courses" : [ 
        {
            "discipline_name" : "management",
            "course_list" : [ 
                {
                    "course_type" : "Master in Business Administration [MBA]",
                    "program_name_list" : [ 
                        {
                            "program_name" : "Master in Business Administration [MBA] (Finance)",
                            "fees" : 40000,
                            "duration" : "48"
                        }
                    ]
                }
            ]
        }
    ]
}]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...