Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8427019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:41:04+00:00 2026-06-10T04:41:04+00:00

I am using mongodb-engine to access MongoDB from a Django project. Normal get, insert

  • 0

I am using mongodb-engine to access MongoDB from a Django project. Normal get, insert and update works quite well, but now would I like to use the geoNear functionality. I can just not figure out a way to call it from Django.

I have tried MyModel.objects.raw(...) and also MyModel.objects.raw_query(...), but the result is not really as expected.

The query will be something like this one (it works from the Mongo shell)

db.runCommand({ geoNear : "mymodel", near : [3, 0], spherical : true, maxDistance : 10 })

And the model uses MongoDBManager

class MyModel(model.Model):
    objects = MongoDBManager()
    ...

has anyone successfully tried that?

Thx Simon

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:41:05+00:00Added an answer on June 10, 2026 at 4:41 am

    I guess the use of the MongoDB db.runCommand(), which is needed for queries with geoNear, is just not possible with the current version of mongodb-enginge. I am using a raw_query with the normal near syntax now and convert the distance between the 2 lat/lon points myself to miles (and the other way around).

    lat_lon_dist = distance_to_lat_long(dist_in_miles)
    l = Listing.objects.raw_query({
                           'geo_location' : {
                                         '$maxDistance': lat_lon_dist,
                                         '$near' : { 'latitude': lat, 'longitude': lon },
                                         }
                           })
    ...
    EARTH_RADIUS = { 
                    'km': 6371, 
                    'mi': 3959 
                    }
    
    ''' returns the distance between two lat/lon points in miles or kilometers '''
    def lat_lon_to_distance(lat1, lon1, lat2, lon2, unit='mi'):
        lat1 = math.radians(lat1)
        lon1 = math.radians(lon1)
        lat2 = math.radians(lat2)
        lon2 = math.radians(lon2)
        return math.acos(math.sin(lat1)*math.sin(lat2) + 
                      math.cos(lat1)*math.cos(lat2) *
                      math.cos(lon2-lon1)) * EARTH_RADIUS[unit];
    
    '''
    converts a distance in miles or kilometer to a difference between two lat/lon points
    the result is just approximately!
    '''
    def distance_to_lat_long(distance, unit='mi'):
        return distance / math.radians(EARTH_RADIUS[unit])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the django-mongodb-engine, django-nonrel, djangotoolbox projects / packages to get django talking with
I'm using MongoDB as a backend for my project, but I don't specifically want
I am using django-nonrel and django-mongodb-engine I have a Django model stored on PostgreSQL
I am using django-nonrel and django-mongodb engine. In engine's documentation , it says that
I'm considering using mongodb on a new project, but before delving in, I'd like
I'm using Django 1.3beta and django-mongodb-engine for database backend. Problem is when I save
Using MongoDB C# driver ( http://github.com/samus/mongodb-csharp ), seems that I'm unable to get the
I am using MongoDB to store data. In my project I am connecting multiple
I am using mongoDB for a new project at work and I got into
I'm currently using MongoDB to record application logs, and while I'm quite happy with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.