Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
calculate distance using aggregate mongodb

i have a problem with calculate distance.

i have data in database like this :

  1. longlat: [-6.117223545020398, 106.72738171204378].

in there, i'am using mongodb. and i using package geolib to get calculate distance. when i calculate the distance, it always get null, but when the field longitude and latitude, i set manual value, it get the value.

CampModel.aggregate([
    {
      $addFields: {
        longitude: {
          $arrayElemAt: ['$longlat', 0],
        },
        latitude: {
          $arrayElemAt: ['$longlat', 1],
        },
        distance: getDistance(
          {
            longitude: -6.139236985993344,
            latitude: 106.73070885735316,
          },
          {
            longitude: '$longitude',
            latitude: '$latitude',
          },
        ),
      },
    },
    {
      $project: {
        createdAt: '$createdAt',
        distance: '$distance',
      },
    },
  ]);

thank you.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!