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 6352505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:13:07+00:00 2026-05-24T22:13:07+00:00

I am using Pymongo to access Mongo db. I want to search for all

  • 0

I am using Pymongo to access Mongo db. I want to search for all people nearby a specified location with name contains a string. For example, I want to search all people nearby [105.0133, 21.3434] and name contains ‘Mark’. So I write the query like this:

db.users.find({ "location.coords": { "$nearSphere": [105.0133, 21.3434], "$maxDistance": 10/EARTH_RADIUS }, "name": "/Mark/" })

(I have an index “location.coords” in my “users” collection)

The query works fine in Mongodb console, but while execute by Pymongo, the dictionary being re-sort like this:

{ "name": "/Mark/", "location.coords": { "$nearSphere": [105.0133, 21.3434], "$maxDistance": 10/EARTH_RADIUS } }

(The “name” key is before “location.coords”, that is not what I expected – also Mongodb expected)

That causes Mongodb cannot understand the query and returns no results. Can anyone help me to figure out how to force the Pymongo does not re-sort my dictionary.

Thanks and regards

  • 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-05-24T22:13:09+00:00Added an answer on May 24, 2026 at 10:13 pm

    The dictionary type is inherently orderless. From the python documentation:

    It is best to think of a dictionary as an unordered set of key: value
    pairs, with the requirement that the keys are unique (within one
    dictionary).

    If you want to index your dictionary in a specific order, you’ll have to store your order somehow. One easy way to do this is to keep your keys in a list, like:

    mongo_keys = ["location.coords", "name"]
    for k in mongo_keys:
        do_something(mongo_result[k])
    

    You also might want to investigate:

    class collections.OrderedDict([items])

    Return an instance of a dict
    subclass, supporting the usual dict methods. An OrderedDict is a dict
    that remembers the order that keys were first inserted. If a new entry
    overwrites an existing entry, the original insertion position is left
    unchanged. Deleting an entry and reinserting it will move it to the
    end.

    Unfortunately if you need more help than that, you’ll need to provide more details of your situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to find names of all collections using PyMongo and find all fields in
I am using pymongo driver. Supposedly, one can use a string to query the
I've created geospatial index on my collection using the statement with PyMongo : self.geo_collection.create_index([('location',pymongo.GEO2D)],\
Using Nunit, I want to be able to write a test fixture that will
I am trying to perform a regex query using PyMongo against a MongoDB server.
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
I am unable to install pymongo using easy_install on python 3.2. c:\Python32\Scripts>easy_install pymongo ...
For one of my projects I prefered using Django+Mongo . Why should I use
I am a mongodb beginner and I use pymongo. I want to know it
Using CRM 4, I have an entity form that contains a tab with an

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.