Guest User

Untitled

a guest
Feb 3rd, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. I'm trying to use a distinct into my mongodb query. Here is my current query where I need to iterate all the data to create a proper array with only the last position:
  2.  
  3. $filter = [
  4. 'car.ref' => [
  5. '$in' => $cars,
  6. ],
  7. 'position.dateTime' => [
  8. '$gte' => $startPeriod,
  9. '$lte' => $endPeriod,
  10. ],
  11. ];
  12.  
  13. $options = [
  14. 'sort' => [
  15. 'position.dateTime' => 1,
  16. ],
  17. ];
  18. $query = new \MongoDB\Driver\Query($filter, $options);
  19. $cursor = $mongo->executeQuery('cars_positions.positions', $query);
  20. If I do this :
  21.  
  22. foreach($cursor as $key => $document) {
  23. var_dump($document);
  24. }
  25. It display a lot of object like this :
  26.  
  27. object(stdClass)[115]
  28. public '_id' =>
  29. object(MongoDB\BSON\ObjectID)[112]
  30. public 'oid' => string '587eb883c86cbf3831dff1ad' (length=24)
  31. public 'car' =>
  32. object(stdClass)[113]
  33. public 'type' => string 'sport' (length=6)
  34. public 'ref' => string 'car1' (length=7)
  35. public 'position' =>
  36. object(stdClass)[114]
  37. public 'dateTime' => string '2017-01-18T23:58:09' (length=19)
  38. public 'latitude' => string '0000.1111' (length=9)
  39. public 'hemesphere' => string 'S' (length=1)
  40. public 'longitude' => string '05563.1254' (length=10)
Advertisement
Add Comment
Please, Sign In to add comment