Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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:
- $filter = [
- 'car.ref' => [
- '$in' => $cars,
- ],
- 'position.dateTime' => [
- '$gte' => $startPeriod,
- '$lte' => $endPeriod,
- ],
- ];
- $options = [
- 'sort' => [
- 'position.dateTime' => 1,
- ],
- ];
- $query = new \MongoDB\Driver\Query($filter, $options);
- $cursor = $mongo->executeQuery('cars_positions.positions', $query);
- If I do this :
- foreach($cursor as $key => $document) {
- var_dump($document);
- }
- It display a lot of object like this :
- object(stdClass)[115]
- public '_id' =>
- object(MongoDB\BSON\ObjectID)[112]
- public 'oid' => string '587eb883c86cbf3831dff1ad' (length=24)
- public 'car' =>
- object(stdClass)[113]
- public 'type' => string 'sport' (length=6)
- public 'ref' => string 'car1' (length=7)
- public 'position' =>
- object(stdClass)[114]
- public 'dateTime' => string '2017-01-18T23:58:09' (length=19)
- public 'latitude' => string '0000.1111' (length=9)
- public 'hemesphere' => string 'S' (length=1)
- public 'longitude' => string '05563.1254' (length=10)
Advertisement
Add Comment
Please, Sign In to add comment