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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:06:15+00:00 2026-05-26T04:06:15+00:00

I have a collections names locations with data structures like: { _id : ObjectId(4e95263f1783ae8487be26d4),

  • 0

I have a collections names locations with data structures like:

{ 
  "_id" : ObjectId("4e95263f1783ae8487be26d4"),
  "name" : "test 1", 
  "location" : { 
     "coordinate" : { 
        "latitude" : 40.731987, 
        "longitude" : -73.999701
     },
     "address": "xxxxxxx"
  }
}

and want to make geo queries against location.coordinate field.

When I’m trying to add index I get following results:

$> db.locations.ensureIndex( { "location.coordinate" : "2d" } )
$> **** SyntaxError: syntax error (shell):0

Is it possible to use geospatial index for such structure?

  • 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-26T04:06:16+00:00Added an answer on May 26, 2026 at 4:06 am

    Since mongodb is based on GeoJSON format, its better to have the longitude element first

    "location" : { 
         "coordinate" : {        
            "longitude" : -73.999701,
            "latitude" : 40.731987 
         },
    

    In the mongodb geospatial page, you can see that in multiple places

    By default, the index assumes you are indexing longitude/latitude and
    is thus configured for a [-180..180) value range.

    and

    The code assumes that you are using decimal degrees in (longitude,
    latitude) order. This is the same order used for the GeoJSON spec.
    Using (latitude, longitude) will result in very incorrect results, but
    is often the ordering used elsewhere, so it is good to double-check.
    The names you assign to a location object (if using an object and not
    an array) are completely ignored, only the ordering is detected.

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

Sidebar

Related Questions

I have a collection: { _id - ObjectId name - string location - string
Say I have 2 parallel collections, eg: a list of people's names in a
I have a IEnumerable<T> collection with Name, FullName and Address. The Address looks like
I have a model that includes attributes like company_name, posted (a date), location (lat/lng
I have 3 collection datatable that shows in this below Month: January ID NAME
I have a collection of objects which describe an image-name, its size and it's
I have a collection of elements, each one with a name and a subcollection
I have a DataTable with a Name column. I want to generate a collection
I have a class CollectionOfThings . As its name suggests its a simple collection
In many places in our code we have collections of objects, from which we

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.