{"action":"created","comment":{"url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/comments/100491099","pull_request_review_id":21199469,"id":100491099,"diff_hunk":"@@ -1,27 +1,53 @@\n const log = require('../../app/lib/logger');\n-const docDB = require('../../config/config').docDB;\n-const queries = require('../lib/queries');\n-const filterServices = require('../lib/filterServices');\n-\n-function getNearbyServices(req, searchPoint, limits, next) {\n-  const geoSpatialQuery = queries.geoSpatialQuery(searchPoint, limits.searchRadius);\n-\n-  req.app.locals.docDBClient\n-    .queryDocuments(docDB.collectionUrl, geoSpatialQuery)\n-    .toArray((err, results) => {\n-      if (err) {\n-        log.error({ err }, 'DocumentDB query failed');\n-        next(err);\n-      } else {\n-        log.debug(`${results.length} RESULTS returned...`);\n-\n-        log.debug('filter-and-sort-services-start');\n-        const filteredServices = filterServices(results, limits);\n-        log.debug('filter-and-sort-services-end');\n+const MongoClient = require('mongodb').MongoClient;\n+const co = require('co');\n+const mongodbConfig = require('../../config/config').mongodb;\n+const filterServices = require('./filterServices');\n+const VError = require('verror').VError;\n \n-        next(null, filteredServices);\n+const connectionString = mongodbConfig.connectionString;\n+\n+function getNearbyServices(searchPoint, limits, next) {\n+  co(function* a() {\n+    const db = yield MongoClient.connect(connectionString);\n+    log.debug(`Connected to ${mongodbConfig.connectionString}`);\n+\n+    const col = db.collection(mongodbConfig.collection);\n+\n+    col.aggregate([{\n+      $geoNear: {\n+        near: { type: 'Point', coordinates: searchPoint.coordinates },\n+        distanceField: 'dist',","path":"app/lib/getNearbyServices.js","position":40,"original_position":40,"commit_id":"8e373d193e1ea356b2f07c3953301ec564380f3f","original_commit_id":"5a8d1fa3b60e0cc9d93ddbccd9bb98c23dcb146e","user":{"login":"beseven","id":1902266,"avatar_url":"https://avatars.githubusercontent.com/u/1902266?v=3","gravatar_id":"","url":"https://api.github.com/users/beseven","html_url":"https://github.com/beseven","followers_url":"https://api.github.com/users/beseven/followers","following_url":"https://api.github.com/users/beseven/following{/other_user}","gists_url":"https://api.github.com/users/beseven/gists{/gist_id}","starred_url":"https://api.github.com/users/beseven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beseven/subscriptions","organizations_url":"https://api.github.com/users/beseven/orgs","repos_url":"https://api.github.com/users/beseven/repos","events_url":"https://api.github.com/users/beseven/events{/privacy}","received_events_url":"https://api.github.com/users/beseven/received_events","type":"User","site_admin":false},"body":"Changing the distanceField here and subsequently everywhere  breaks the sorting. api-test_1               |   32 passing (942ms)\r\napi-test_1               |   1 failing\r\napi-test_1               | \r\napi-test_1               |   1) filterServices happy path should return the nearest obj first:\r\napi-test_1               | \r\napi-test_1               |       AssertionError: expected 'A' to equal 'B'\r\napi-test_1               |       + expected - actual\r\napi-test_1               | \r\napi-test_1               |       -A\r\napi-test_1               |       +B\r\napi-test_1               |       \r\napi-test_1               |       at Context.it (test/unit/lib/filterServices.js:76:50)\r\n\r\nI believe the aggregate results are past to the filtering but the sorting is also changing the data so the result give me an outlier (which is why I went with a different var to begin with, IIRC)\r\n![screenshot-localhost 3000 2017-02-10 08-38-29](https://cloud.githubusercontent.com/assets/1902266/22819946/83394d98-ef6c-11e6-9100-3f5d28277490.png)\r\n\r\nChanging to `dist` and raising an issue to investigate further if needed.\r\n","created_at":"2017-02-10T08:40:31Z","updated_at":"2017-02-10T08:40:31Z","html_url":"https://github.com/nhsuk/nearby-services-api/pull/30#discussion_r100491099","pull_request_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/comments/100491099"},"html":{"href":"https://github.com/nhsuk/nearby-services-api/pull/30#discussion_r100491099"},"pull_request":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30","id":101741638,"html_url":"https://github.com/nhsuk/nearby-services-api/pull/30","diff_url":"https://github.com/nhsuk/nearby-services-api/pull/30.diff","patch_url":"https://github.com/nhsuk/nearby-services-api/pull/30.patch","issue_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/30","number":30,"state":"open","locked":false,"title":"Feature/mongo+data","user":{"login":"beseven","id":1902266,"avatar_url":"https://avatars.githubusercontent.com/u/1902266?v=3","gravatar_id":"","url":"https://api.github.com/users/beseven","html_url":"https://github.com/beseven","followers_url":"https://api.github.com/users/beseven/followers","following_url":"https://api.github.com/users/beseven/following{/other_user}","gists_url":"https://api.github.com/users/beseven/gists{/gist_id}","starred_url":"https://api.github.com/users/beseven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beseven/subscriptions","organizations_url":"https://api.github.com/users/beseven/orgs","repos_url":"https://api.github.com/users/beseven/repos","events_url":"https://api.github.com/users/beseven/events{/privacy}","received_events_url":"https://api.github.com/users/beseven/received_events","type":"User","site_admin":false},"body":"Changes to use docker, a docker image for mongo, fix issues after the aggregate to avoid changing the api contract, tests in Travis","created_at":"2017-01-16T18:51:31Z","updated_at":"2017-02-10T08:40:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"11cbc31ed6446ddfad4d2f3053442260d17e5043","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30/commits","review_comments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30/comments","review_comment_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/30/comments","statuses_url":"https://api.github.com/repos/nhsuk/nearby-services-api/statuses/8e373d193e1ea356b2f07c3953301ec564380f3f","head":{"label":"nhsuk:featrue/mongo+data","ref":"featrue/mongo+data","sha":"8e373d193e1ea356b2f07c3953301ec564380f3f","user":{"login":"nhsuk","id":18658529,"avatar_url":"https://avatars.githubusercontent.com/u/18658529?v=3","gravatar_id":"","url":"https://api.github.com/users/nhsuk","html_url":"https://github.com/nhsuk","followers_url":"https://api.github.com/users/nhsuk/followers","following_url":"https://api.github.com/users/nhsuk/following{/other_user}","gists_url":"https://api.github.com/users/nhsuk/gists{/gist_id}","starred_url":"https://api.github.com/users/nhsuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhsuk/subscriptions","organizations_url":"https://api.github.com/users/nhsuk/orgs","repos_url":"https://api.github.com/users/nhsuk/repos","events_url":"https://api.github.com/users/nhsuk/events{/privacy}","received_events_url":"https://api.github.com/users/nhsuk/received_events","type":"Organization","site_admin":false},"repo":{"id":73835517,"name":"nearby-services-api","full_name":"nhsuk/nearby-services-api","owner":{"login":"nhsuk","id":18658529,"avatar_url":"https://avatars.githubusercontent.com/u/18658529?v=3","gravatar_id":"","url":"https://api.github.com/users/nhsuk","html_url":"https://github.com/nhsuk","followers_url":"https://api.github.com/users/nhsuk/followers","following_url":"https://api.github.com/users/nhsuk/following{/other_user}","gists_url":"https://api.github.com/users/nhsuk/gists{/gist_id}","starred_url":"https://api.github.com/users/nhsuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhsuk/subscriptions","organizations_url":"https://api.github.com/users/nhsuk/orgs","repos_url":"https://api.github.com/users/nhsuk/repos","events_url":"https://api.github.com/users/nhsuk/events{/privacy}","received_events_url":"https://api.github.com/users/nhsuk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nhsuk/nearby-services-api","description":null,"fork":false,"url":"https://api.github.com/repos/nhsuk/nearby-services-api","forks_url":"https://api.github.com/repos/nhsuk/nearby-services-api/forks","keys_url":"https://api.github.com/repos/nhsuk/nearby-services-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nhsuk/nearby-services-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nhsuk/nearby-services-api/teams","hooks_url":"https://api.github.com/repos/nhsuk/nearby-services-api/hooks","issue_events_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/events{/number}","events_url":"https://api.github.com/repos/nhsuk/nearby-services-api/events","assignees_url":"https://api.github.com/repos/nhsuk/nearby-services-api/assignees{/user}","branches_url":"https://api.github.com/repos/nhsuk/nearby-services-api/branches{/branch}","tags_url":"https://api.github.com/repos/nhsuk/nearby-services-api/tags","blobs_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nhsuk/nearby-services-api/statuses/{sha}","languages_url":"https://api.github.com/repos/nhsuk/nearby-services-api/languages","stargazers_url":"https://api.github.com/repos/nhsuk/nearby-services-api/stargazers","contributors_url":"https://api.github.com/repos/nhsuk/nearby-services-api/contributors","subscribers_url":"https://api.github.com/repos/nhsuk/nearby-services-api/subscribers","subscription_url":"https://api.github.com/repos/nhsuk/nearby-services-api/subscription","commits_url":"https://api.github.com/repos/nhsuk/nearby-services-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/nhsuk/nearby-services-api/contents/{+path}","compare_url":"https://api.github.com/repos/nhsuk/nearby-services-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nhsuk/nearby-services-api/merges","archive_url":"https://api.github.com/repos/nhsuk/nearby-services-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nhsuk/nearby-services-api/downloads","issues_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues{/number}","pulls_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls{/number}","milestones_url":"https://api.github.com/repos/nhsuk/nearby-services-api/milestones{/number}","notifications_url":"https://api.github.com/repos/nhsuk/nearby-services-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nhsuk/nearby-services-api/labels{/name}","releases_url":"https://api.github.com/repos/nhsuk/nearby-services-api/releases{/id}","deployments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/deployments","created_at":"2016-11-15T16:56:29Z","updated_at":"2017-02-06T16:17:21Z","pushed_at":"2017-02-09T13:16:40Z","git_url":"git://github.com/nhsuk/nearby-services-api.git","ssh_url":"git@github.com:nhsuk/nearby-services-api.git","clone_url":"https://github.com/nhsuk/nearby-services-api.git","svn_url":"https://github.com/nhsuk/nearby-services-api","homepage":null,"size":5928,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":1,"default_branch":"master"}},"base":{"label":"nhsuk:master","ref":"master","sha":"115c5046afc4698003778bba50ff075a04ba9138","user":{"login":"nhsuk","id":18658529,"avatar_url":"https://avatars.githubusercontent.com/u/18658529?v=3","gravatar_id":"","url":"https://api.github.com/users/nhsuk","html_url":"https://github.com/nhsuk","followers_url":"https://api.github.com/users/nhsuk/followers","following_url":"https://api.github.com/users/nhsuk/following{/other_user}","gists_url":"https://api.github.com/users/nhsuk/gists{/gist_id}","starred_url":"https://api.github.com/users/nhsuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhsuk/subscriptions","organizations_url":"https://api.github.com/users/nhsuk/orgs","repos_url":"https://api.github.com/users/nhsuk/repos","events_url":"https://api.github.com/users/nhsuk/events{/privacy}","received_events_url":"https://api.github.com/users/nhsuk/received_events","type":"Organization","site_admin":false},"repo":{"id":73835517,"name":"nearby-services-api","full_name":"nhsuk/nearby-services-api","owner":{"login":"nhsuk","id":18658529,"avatar_url":"https://avatars.githubusercontent.com/u/18658529?v=3","gravatar_id":"","url":"https://api.github.com/users/nhsuk","html_url":"https://github.com/nhsuk","followers_url":"https://api.github.com/users/nhsuk/followers","following_url":"https://api.github.com/users/nhsuk/following{/other_user}","gists_url":"https://api.github.com/users/nhsuk/gists{/gist_id}","starred_url":"https://api.github.com/users/nhsuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nhsuk/subscriptions","organizations_url":"https://api.github.com/users/nhsuk/orgs","repos_url":"https://api.github.com/users/nhsuk/repos","events_url":"https://api.github.com/users/nhsuk/events{/privacy}","received_events_url":"https://api.github.com/users/nhsuk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nhsuk/nearby-services-api","description":null,"fork":false,"url":"https://api.github.com/repos/nhsuk/nearby-services-api","forks_url":"https://api.github.com/repos/nhsuk/nearby-services-api/forks","keys_url":"https://api.github.com/repos/nhsuk/nearby-services-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nhsuk/nearby-services-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nhsuk/nearby-services-api/teams","hooks_url":"https://api.github.com/repos/nhsuk/nearby-services-api/hooks","issue_events_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/events{/number}","events_url":"https://api.github.com/repos/nhsuk/nearby-services-api/events","assignees_url":"https://api.github.com/repos/nhsuk/nearby-services-api/assignees{/user}","branches_url":"https://api.github.com/repos/nhsuk/nearby-services-api/branches{/branch}","tags_url":"https://api.github.com/repos/nhsuk/nearby-services-api/tags","blobs_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nhsuk/nearby-services-api/statuses/{sha}","languages_url":"https://api.github.com/repos/nhsuk/nearby-services-api/languages","stargazers_url":"https://api.github.com/repos/nhsuk/nearby-services-api/stargazers","contributors_url":"https://api.github.com/repos/nhsuk/nearby-services-api/contributors","subscribers_url":"https://api.github.com/repos/nhsuk/nearby-services-api/subscribers","subscription_url":"https://api.github.com/repos/nhsuk/nearby-services-api/subscription","commits_url":"https://api.github.com/repos/nhsuk/nearby-services-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/nhsuk/nearby-services-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/nhsuk/nearby-services-api/contents/{+path}","compare_url":"https://api.github.com/repos/nhsuk/nearby-services-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nhsuk/nearby-services-api/merges","archive_url":"https://api.github.com/repos/nhsuk/nearby-services-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nhsuk/nearby-services-api/downloads","issues_url":"https://api.github.com/repos/nhsuk/nearby-services-api/issues{/number}","pulls_url":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls{/number}","milestones_url":"https://api.github.com/repos/nhsuk/nearby-services-api/milestones{/number}","notifications_url":"https://api.github.com/repos/nhsuk/nearby-services-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nhsuk/nearby-services-api/labels{/name}","releases_url":"https://api.github.com/repos/nhsuk/nearby-services-api/releases{/id}","deployments_url":"https://api.github.com/repos/nhsuk/nearby-services-api/deployments","created_at":"2016-11-15T16:56:29Z","updated_at":"2017-02-06T16:17:21Z","pushed_at":"2017-02-09T13:16:40Z","git_url":"git://github.com/nhsuk/nearby-services-api.git","ssh_url":"git@github.com:nhsuk/nearby-services-api.git","clone_url":"https://github.com/nhsuk/nearby-services-api.git","svn_url":"https://github.com/nhsuk/nearby-services-api","homepage":null,"size":5928,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30"},"html":{"href":"https://github.com/nhsuk/nearby-services-api/pull/30"},"issue":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/30"},"comments":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/nhsuk/nearby-services-api/statuses/8e373d193e1ea356b2f07c3953301ec564380f3f"}}}}
{"actor":{"display_login":"beseven"}}