Поиск общих элементов в списке словарей и категоризация на основе ранжирования
Я хотел бы выяснить «Домены», которые являются общими в обоих списках, и подсчитать количество доменов в предоставленной верхней границе ранжирования. .
db.collection.find()
{
_id : objectId("12345"),
"tags": "txt",
"list_1" : {
{
"Domain": "abc.com",
"Rank" : 1
},
{
"Domain": "zxt.com",
"Rank" : 9999999
},
{
"Domain": "helloworld.com",
"Rank": 1000000
},
{
"Domain": "foo.com",
"Rank": 10000
}
....
"list_2" : {
{
"Domain": "abc.com",
"Rank" : 100000
},
{
"Domain": "sadsadasd.com",
"Rank" : 102
}
....
"list_3" ...
.
.
.
"list_n" ...
.
.
"super_list": {
{
"Domain": "abc.com",
"Rank": 50
},
{
"Domain": "helloworld.com",
"Rank": 2999999
},
{
"Domain": "foo.com",
"Rank": 9999999
}
....
}
....
}
В приведенном выше примере: list_1 и list_2 имеют общие домены, но разные ранги. Может быть «n» количество списков. Аналогично, super_list - это супер-набор большинства списков. Супер установить как бы не все списки.
Я хотел бы найти следующие случаи:
1) Domains that are common in both list_1 and list_2 or given 2 lists where ranking does not matter or opt out
Ex. list_1 and list_2 would give ouput as abc.com though they have different ranks.
2) Domains from list_1 which are common and lower than upper bound rank of list_2
Example: abc.com is common in both. But the ranking differs in list_1 and list_2. In this case, I would have some upperbound rank such as 99999. The query should not give common domains as "abc.com" as the ranking is 100000 in list_2
3) Domains that are common to list_1 and super_list where rank upper bound in super_list matter
Example: Let's say: The upper bound is 3 Million rank. We would like to get common domains that are under or equal to 3 Million in super_list from list_1
Here the output would be : helloworld.com which is under 3 Mil in super_list. The foo.com from super_list will be printed as it is higher than 3 Mil rank in super_list.
Вывод mongodb