Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geoNear doesn't work #2

Open
mgpeng opened this issue Sep 15, 2018 · 5 comments
Open

geoNear doesn't work #2

mgpeng opened this issue Sep 15, 2018 · 5 comments

Comments

@mgpeng
Copy link

mgpeng commented Sep 15, 2018

Hi, Simon
I followed your book to code few days, it is amazing, but in chapter 6,
geoNear is deprecated in new version Mongodb and Mongoose, and I checked
all documents , there are not any details about geoNear even near and nearSpherical,
and I tried aggregate, query, and I still found solution. Simon, can you help us to fix this ?

@YuenEsc
Copy link

YuenEsc commented Oct 29, 2018

Hi @mgpeng the file I'm sharing is the location.js file that should be in the api_server folder I'm currently following the way it was done in the first version of this book but I use nearly all of the updated versions of the frameworks, so I will share a screenshot of my package.json too
locations-js.txt
So, the new way to use the geoNear is here at the official documentation, I just followed it.
And if you have the locations that the author have been using so far then you could test it with a rest client for example
http://localhost:3000/api/locations?lng=-0.9690884&lat=51.4550410 with a GET method
you should see some result like this if everything is fine
[{"distance":0,"name":"Starcups","address":"125 High Street, Reading, RG6 1PS","rating":3,"_id":"5bd3ee9ac97ce053695eeae6"},{"distance":0,"name":"Cafe Hero","address":"125 High Street, Reading, RG6 1PS","rating":3,"_id":"5bd49b446894823f24ac7efb"}]

screenshot from 2018-10-28 21-21-37

screenshot from 2018-10-28 21-15-51

@g0ochoa
Copy link

g0ochoa commented Jan 5, 2019

@YuenEsc I am now going thru the book myself and I hit the ame problem. I copied your code, but when i enter the URL with th coordinates , results comes back empty . []. when i print the point.coordinates.lng and point.coordinates.lat, I am getting value as undefined. any idea what could i be doing wrong?

@g0ochoa
Copy link

g0ochoa commented Jan 5, 2019

nevermind @YuenEsc . i figured it out. :) i had my lng and lat backwards in my db. Beginners mistake, I am still really new to programming in general. This book is awesome though!!! I am getting MEANer each day!

@jcalcagni
Copy link

I'm still having the Loc.geoNear is not a function issue

all of my locations have a long/lat of the same value (41.702741 & -71.430348)
if i try a GET at
localhost:3000/api/locations?lng=41.702741&lat=-71.430348&maxDistance=200

i receive the error
Loc.geoNear is not a function

@Ifejeremiah
Copy link

Ifejeremiah commented Oct 7, 2021

Hello !
I hope you all have gotten the solutions?
These are some of the things about code and books, and information being obsolete.
But @simonholmes and @cliveharber have done an amazing job that would last long enough.

So for other people that would get to read this amazing book, here are some minor corrections in Chapter 06.

  • For limiting geoNear results by number, use "$LIMIT" instead of "LIMIT" in the "const geoOptions". That is all there is to that chapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants