How to avoid memory problems when running php mongodb aggregate group function? -


i'm running memory problems when try group list field.

input: it's list of items category , fields:

{ category: "catname1", field1: "value11", field2: "value21", ... }, { category: "catname2", field1: "value12", field2: "value22", ... }, { category: "catname3", field1: "value13", field2: "value23", ... }, { category: "catname4", field1: "value14", field2: "value24", ... }, .. 

output: should list of categories, each list of corresponding items:

{ category: "catname1", items: [     { field1: "value12", field2: "value22", ... },     { field1: "value14", field2: "value24", ... }, .. ] }, { category: "catname2", items: [     { field1: "value12", field2: "value22", ... },     { field1: "value14", field2: "value24", ... }, .. ] }, 

//edit: tried different versions, removed 1 better readability.

partial solution: works small lists, runs out of memory when have 1000 categories 1000 items each. :(

$cursor = $collection->aggregate(     array(         array(             '$match' => array(                 .. filters here ...             ) ),         array(             '$group' => array(                     '_id' => '$category',                     'items' => array( '$addtoset' => array(                         'field1' => '$field1',                         'field2' => '$field2',                         'field3' => '$field3',                         'field4' => '$field4'                     ) ) ) ) ) ); 

when try input list beginning, works fine. try group them somehow fails. ideas why or how fix it?

you schema exact copy of people use in sql environment.

try changing schema to

{     "category": "cat1",     "values": {         "item1": "value1",         "item1": "value2"     }  } 

this should work fine long number of different keys not grow above 100 or 1000.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -