123456789101112131415161718192021222324252627282930 |
- <?php
- require_once("../vendor/autoload.php");
- use MongoDB\Client;
- // Requires the MongoDB PHP Driver
- // https://www.mongodb.com/docs/drivers/php/
- $userInput = file_get_contents('php://input');
- $userInputData = json_decode($userInput, true);
- if ($userInputData !== null) {
- $client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
- $collection = $client->selectCollection('kpmaster', 'kpu');
- $cursor = $collection->aggregate([['$geoNear' => ['near' => ['type' => 'Point', 'coordinates' => [$userInputData["long"], $userInputData["lat"]]], 'spherical' => true, 'query' => ['srvs' => ['$all' => [$userInputData["service"]]]], 'distanceField' => 'Dis', 'maxDistance' => $userInputData["maxdistance"], 'includeLocs' => 'loc']], ['$project' => ['ID' => '$oid', 'Name' => '$fn', 'Distance' => '$Dis', 'Location' => '$loc']]]);
- $responseDataJson = iterator_to_array($cursor);
- $dCount = Count($responseDataJson);
- if ($dCount > 0) {
- $message['status'] = true;
- $message['count'] = $dCount;
- $message['data'] = $responseDataJson;
- } else {
- $message['status'] = true;
- $message['count'] = $dCount;
- $message['statusMessage'] = "No Records Found!";
- }
- } else {
- $message['status'] = false;
- $message['statusCode'] = "KP001";
- $message['statusMessage'] = "Data Not Received";
- }
- echo json_encode($message);
|