mongodb - Grouping elements having same groupid after filtering -
we have documents "metadata" element having following structure:
... "metadata": [ { "metaname": "first_name", "value": "john", "group": "id_1" }, { "metaname": "last_name", "value": "doe", "group": "id_1" }, { "metaname": "age", "value": "55", "group": "id_1" }, { "metaname": "first_name", "value": "hugo", "group": "id_2" }, { "metaname": "last_name", "value": "cabret","group": "id_2" }, { "metaname": "town", "value": "paris", "group": "id_2" }, { "metaname": "first_name", "value": "john", "group": "id_3" }, { "metaname": "last_name", "value": "ford", "group": "id_3" }, { "metaname": "age", "value": "78", "group": "id_3" } ] ... we want make search involving both "metaname" , "value", have positive hit if group same. can have unlimited "metaname" in each group, e.g. "metaname": "town" or "metaname":"age" etc etc can (optionally) have multiple metadata.
note "id_x" string made initial part (id) unique each document, appended ascending ordinal (1,2,3...). e.g. document can have "group": "77de-66ea-190c-bbh5_1", "77de-66ea-190c-bbh5_2", "77de-66ea-190c-bbh5_3" etc. , 2 different documents can't have same id. don't know id_x a priori.
our difficulty find query in "and" efficiently reports hits if results in same group.
e.g. want find docs having "metaname":"first_name" , "value":"john" , "metaname":"last_name" , "value":"cabret", "group" of multiple element found must same. in case, don't have hit (since "group" id_1 "john" , id_2 "cabret".
first of all: possible make query this? have million of documents, , query made via spring data (!) trying find best way implement it. unable find query that, suggestion welcome, documentation, hints, remapping / rebuilding / refactoring of data, etc.
thank in advance.
Comments
Post a Comment