php - How do I get an object from this tree in mongoDb? -


how object tree? :

{     "_id" : objectid("33b97aa654bce61322002559"),     "name" : "test",     "children" : [         "_id" : objectid("44b97aa654bce61322002559"),         "name" : "test children",         "children" : [             "_id" : objectid("55b97aa654bce61322002559"),             "name" : "test children children",             "children" : "",             "products" : [                 "_id" : objectid("55b97aa654bce61322002559"),                 "name" : "product 1" //i need object                 "attrib" : [                     "sale" : 1,                     "new" : 1,                     "instock" : 1,                 ]             ],             "products" : ""         ]     ],     "products" : "" } 

levels can number.

  • children
  • -children
  • --children
  • ---children
  • ----children

    $arr = categories::findone(['_id' => '55b97aa654bce61322002559']); debug($arr);

maybe i'm not shaping structure db correctly? thank you.

//return array of objects according key, value, or key , value matching function getobjects(obj, key, val) {     var objects = [];     (var in obj) {         if (!obj.hasownproperty(i)) continue;         if (typeof obj[i] == 'object') {             objects = objects.concat(getobjects(obj[i], key, val));         } else         //if key matches , value matches or if key matches , value not passed (eliminating case key matches passed value not)         if (i == key && obj[i] == val || == key && val == '') { //             objects.push(obj);         } else if (obj[i] == val && key == ''){             //only add if object not in array             if (objects.lastindexof(obj) == -1){                 objects.push(obj);             }         }     }     return objects; } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -