iamshaunjp / rest-api-playlist

Course files for the REST API tutorial series on The Net Ninja Youtube channel
170 stars 168 forks source link

GeoJSON #11

Open whiki opened 6 years ago

whiki commented 6 years ago

You didn't include the GeoJSON object file

whiki commented 6 years ago

getNear is not working for me, saying getNear is not a function

springc1 commented 6 years ago

Hi, have the same issue. could not find GeoJSON object file on GeoJSON side. is it in a branch?

Tapudp commented 6 years ago

Yeah in the video he mentions using the Ninjas.geoNear function but in the Postman software it outputs as geoNear is not function, how to solve that

I've even read the official documentation about the geoNear function but it sounds something more fishy. I don't understand that much. If this can not be solved someone can please help me understand what is going on, and why is the geoNear function not recognising itself.

Funny enough, even VSCode didn't automatically suggested the geoNear function

EDIT: do I have to install those additional file of MongoDB to use the geoNear function like the main bundle might not have those location functions and one might need to add additional libraries to use those. This is a doubt I have in mind, any help suggestion is appreciated

the documentation shows some aggregation parameter/callback as well, what is that ? https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/

Ileshchandra commented 6 years ago

The latest version of mongoose does not support geoNear. you might have to roll back to version 4 of mongoose.

krizten commented 6 years ago
router.get('/ninjas', (req, res, next) => {

    Ninja.aggregate().near({
        near: {
            'type': 'Point',
            'coordinates': [parseFloat(req.query.lng), parseFloat(req.query.lat)]
        },
        maxDistance: 100000,
        spherical: true,
        distanceField: 'dis'
    }).then(ninjas => res.send(ninjas));
});

I got this solution from comments on the YouTube channel. It works for me. I think you should give it a try.

Tapudp commented 6 years ago

@krisdotcode okay sure, though for me it was more like it wasn't able to load the GeoJSON API, but anyways thank you