[Extension] Yiimongodbsuite

hi everybody!

recently, I used the extension for new project but have some problems when using operation ‘array of Embedded Documents’.

database:

Users {

[indent] "nickname" : "xxx",

"mail_address" : "xxxx",

"password" : "xxxx",

"category_list" : [{

  [indent]"category_id" : ObjectId("xxxx"),


  "name" : "xxx",


  "update_date" : "xxxxx"


}, {


  "category_id" : ObjectId("xxxx"),


  "name" : "xxx",


  "update_date" : "xxxxx"


}[/indent]],

"register_date" : "xxxxx",

"last_login_date" : "xxxxx",

"_id" : ObjectId("xxxxxxxx")[/indent]

}

Controller

class Users extends EMongoDocument

{

[indent] public function behaviors()

{

[indent]return array(


  [indent]array(


    [indent]'class'=>'ext.YiiMongoDbSuite.extra.EEmbeddedArraysBehavior',


    'arrayPropertyName'=>'category_list', // name of property


    'arrayDocClassName'=>'CategoryListEmbed' // class name of documents in array[/indent]


  ),[/indent]


);[/indent]

}[/indent]

}

  1. to update category_id = ‘100’

[indent]

  $criteria = new EMongoCriteria;


  $criteria->mail_address('==', 'email_address@yahoo.com');


  $user = Users::model()->find($criteria);





  $category_list = $user->category_list;


  


  if ($category_list) {

[indent] foreach ($category_list $key => $value) {

         [indent] if ($value->category_id == 100) {


              [indent]$value->name = 'new name';


              $category_list[$key] = $value;[/indent]


          }[/indent]


      }





      $user->category_list = $category_list;[/indent]


  }





  $user->save();[/indent]

as above category_id = ‘100’ will be saved with name = ‘new name’ but performance is not high, I’m trying to find other solutions however not found. can someone help me?

  1. When I want get 5 first element of category list, how to get without foreach array.