getting-MEAN-2
getting-MEAN-2 copied to clipboard
geoNear doesn't work
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 ?
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"}]
@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?
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!
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
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.