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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:51:07+00:00 2026-05-26T03:51:07+00:00

My Schema is as follows: mongoose = require ‘mongoose’ ObjectId = mongoose.Schema.ObjectId CheckinSchema =

  • 0

My Schema is as follows:

mongoose = require 'mongoose'
ObjectId  = mongoose.Schema.ObjectId

CheckinSchema = new mongoose.Schema
  text:
    type: String, required: true
  location_latLong:
    lat:
      type: Number
    lon:
      type: Number
  location_country:
    type: String
  addedOn:
    type: Date
    default: Date.now

CheckinSchema.index
  location_latLong: '2d'

exports.CheckinSchema = CheckinSchema

The Model is generated separately. I get an error however when running a query. The error is:

count fails:{ errmsg: "exception: can't find special index: 2d for: { location_latLong: { $wi...", code: 13038, ok: 0.0 }

My query is:

{ location_latLong: { '$within': { '$box': [[ '-100', '-100' ],[ '100', '100' ]] } } }

So my question is…. what gives? How can I properly do Geospatial indexing in Mongoose (using Node.js)

  • 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-26T03:51:09+00:00Added an answer on May 26, 2026 at 3:51 am

    THis is because you have specified the wrong order in your geo index, Since mongodb is based on GeoJSON, its recommented to have the longitude field first

    instead this

    location_latLong:
        lat:
          type: Number
        lon:
          type: Number
    

    use this

    location_latLong:
        lon:
          type: Number
        lat:
          type: Number
    

    The names you assign to a location object (lon,lat keys) are completely ignored, only the ordering is detected.

    In mongodb geospatial page, its recommended 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.

    I have already answered this before.

    Cheer

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

Sidebar

Related Questions

i'm using symfony 1.4, and my schema is as follows: Auditor: columns: id: type:
I have a sample Solr schema as follows isPublic = boolean source = facebook|
I have a DTO type declared as follows: [Serializable] public class PersonDTO { public
I have an app which draws a diagram. The diagram follows a certain schema,
I have a database schema like follows: User 1 ---- * UserRole *----1 Role
I have an XML schema that looks as follows: <xml> <user id=1> <first_name>Bill</first_name> <last_name>Steve</last_name>
I am new to solr, while creating the indexes i am attaching string to
I have an XML configuration as follows: <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:aop=http://www.springframework.org/schema/aop xmlns:tx=http://www.springframework.org/schema/tx xmlns:context=http://www.springframework.org/schema/context xsi:schemaLocation=
The schema is as follows: CREATE TABLE [Structure]( [StructureId] [uniqueidentifier] NOT NULL, [SequenceNumber] [int]
The schema is as follows: Student(Snum, Sname) Course(Cnum, Cname) Professor(Pnum,Pname, Dept, Office) Class(Cnum, Term,

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.