Guest User

Untitled

a guest
Jul 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Array
  2. (
  3. [_id] => MongoId Object
  4. (
  5. [$id] => 4e465de048177e8105000003
  6. )
  7.  
  8. [id_usuario] => MongoId Object
  9. (
  10. [$id] => 4e43b20648177e5305000000
  11. )
  12.  
  13. [mensaje] => lero lero si?
  14. [created_at] => MongoDate Object
  15. (
  16. [sec] => 1313234400
  17. [usec] => 160000
  18. )
  19. [comentarios] => Array
  20. (
  21. [0] => Array
  22. (
  23. [comentario] => hola mundo
  24. [usuario] => [_id] => MongoId Object
  25. (
  26. [$id] => 4e465de048177e8105000003
  27. )
  28. [created_at] => MongoDate Object
  29. (
  30. [sec] => 1313234400
  31. [usec] => 160000
  32. )
  33. )
  34. [1] => Array
  35. (
  36. [comentario] => hola mundo
  37. [usuario] => [_id] => MongoId Object
  38. (
  39. [$id] => 4e465de048177e8105000003
  40. )
  41. [created_at] => MongoDate Object
  42. (
  43. [sec] => 1313234400
  44. [usec] => 160000
  45. )
  46. )
  47. )
  48. )
  49.  
  50. $db->usuarios->find()->sort(array('created_at' => -1))->limit(10)->skip(0);
  51.  
  52. $db->usuarios->find()->sort(array('created_at' => -1))->limit(10)->skip(0);
  53.  
  54. $user = $db->usuarios->find()->sort(array('commentarios.created_at' => -1)->limit(3);
  55. $comments = array_merge($user[0]['commentarios'], $user[1]['commentarios'], $user[2]['commentarios']
  56. $ordered = uasort($comments, 'sorter')
  57.  
  58. function sorter($a, $b) {
  59. return $a['created_date'] < $b['created_date'];
  60. }
Add Comment
Please, Sign In to add comment