I want the code below to retrieve the datas stored to mongodb based on the longitude and latitude but for some reason it returns an empty array.
const express = require('express');
const { db } = require('../models/users');
const router = express.Router();
const User = require('../models/users');
// get a list of users from the db
router.get('/ninjas', function(req, res) {
User.aggregate([
{
$geoNear:
{
near: {type: 'Point',
coordinates: [parseFloat(req.query.lng),
parseFloat(req.query.lat)]},
spherical: true,
maxDistance: 100000,
distanceField: "dist.calculated"
} }
]).then(function( users){
res.send(users);
console.log(users)
});
});
The result gotten in postman:
I will appreciate any help. thank you all in advance