index.php 704 B

123456789101112
  1. <?php
  2. require_once("../vendor/autoload.php");
  3. use MongoDB\Client;
  4. // Requires the MongoDB PHP Driver
  5. // https://www.mongodb.com/docs/drivers/php/
  6. $client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
  7. $collection = $client->selectCollection('kpmaster', 'kpu');
  8. $cursor = $collection->aggregate([['$geoNear' => ['near' => ['type' => 'Point', 'coordinates' => [76.768, 8.736]], 'spherical' => true, 'query' => ['srvs' => ['$all' => ['One']]], 'distanceField' => 'Dis', 'maxDistance' => 2000, 'includeLocs' => 'loc']], ['$project' => ['ID'=>'$oid', 'Name' => '$fn', 'Distance' => '$Dis', 'Location' => '$loc']]]);
  9. echo json_encode(iterator_to_array($cursor));
  10. ?>