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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:54:50+00:00 2026-05-25T13:54:50+00:00

I am finding problem in defining the geo spatial index ‘2d’ as shown below.

  • 0

I am finding problem in defining the geo spatial index ‘2d’ as shown
below. Any clue as to what is going wrong ?

var Address = new Schema({
      loc           : {lat: Number,  lng: Number },
      Address       : String,
      create_date       : {type: Date, default: Date.now}
});
Address.index ({
       loc : "2d"
});

It throws error like,

events.js:45
throw arguments[1]; // Unhandled ‘error’ event
^ Error: point not in range at [object
Object]. (/cygdrive/c/Personal/software/ nodejs/NODE/no
de_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:503:20)

EDIT: added the code

var Address = new Schema({
      type              : {type: String, enum: ['Apartment', 'House', 'Serviced Apartment'], default: 'Apartment'}, 
      loc               : {lat: Number,  lng: Number },
      Address           : String,
      create_date       : {type: Date, default: Date.now}
});

/*
Address.index ({
    loc : "2d"
});
*/

mongoose.connect('mongodb://127.0.0.1:27017/test123', function(err) {
    if (err) {
        console.log("error in mongo connection");
        throw err;
    }
    console.log("connected to mongo");
});

var RentModel = mongoose.model('Rent', Address);



socket = io.listen(app);

socket.sockets.on('connection', function(client){ 

        console.log('inside on connection');

        client.on('register', function(msg){ 
                console.log("msg.geometry.type", msg.geometry.type);

                var rent = new RentModel();
                rent.type = 'Apartment';
                rent.loc.lat = 23;
                rent.loc.lng = 56;
                rent.Address = "LLLLLLLLIIIIIIIOOOOOOONNNNNNNN"

                console.log("before save");
                rent.save(function(err){
                    console.log("rent.save start");
                    if(err) { 
                        throw err; 
                        console.log("error in save");
                    }
                    console.log("saved");

                });

            }); 


            RentModel.find({loc : { $near : [20, 50], $maxDistance: 30 }} , function(err, docs){
                if (err) {
                    console.log("error in finding near", err);
                    throw err;
                }
                console.log('docs.length : ' , docs.length);
                console.log('docs : ',docs)
            })
  • 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-25T13:54:51+00:00Added an answer on May 25, 2026 at 1:54 pm

    It’s also worth noting that you will want longitude to come before latitude in your array. This will not affect you when you are using 2D, but it will when you are using 3D. Mathematically this makes sense as longitude is the X coordinate and latitude is the Y coordinate (x,y), but most of us are familiar with lat coming before long (and one of the best Mongo books out there has an example with lat before long, but it does not cover 2D).

    Ultimately you’re likely going to want to use 3D as 2D calculations are not accurate as you move away from the equator.


    UPDATE: 2015-12-08
    The above is no longer relevant – please see updated answers/API docs

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

Sidebar

Related Questions

Hi I'm finding this problem to manifest differently on various setups. I've had any
I have trouble finding the problem with the function below. The first parameters is
I am facing problem finding any solution for converting my PDF to HTMl/xml.This requirement
I'm finding this problem every now and then in my production website, and it
I have a problem finding references to this subject and would appreciate some help.
I'm really having a problem finding out how to fix this. I cannot seem
I am using MS AJAX ASP.NET Components (Calendar Extender) and I'm finding this problem.
I'm working on writing some automation code and I'm running into a problem finding
So, I understand the problem of finding the longest simple path in a graph
I am working on a geometry problem that requires finding the intersection of two

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.