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)
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
use this
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
and
I have already answered this before.
Cheer