mongodb - MongoError: can't find any special indices: 2d (needs index), 2dsphere (needs index) -


i attempting use mongodb's geospatial indexing querying latitude , longitude points around point using mongodb's find method. keep getting error:

mongoerror: can't find special indices: 2d (needs index), 2dsphere (needs index)

i'm not sure documentation after googling hour. can't find explanations. here schema created using mongoose:

var mongoose = require('mongoose'); var schema = mongoose.schema;  var eventschema = new schema ({   name: string,   description: string,   location: {type: [string], index: '2dsphere'},   time: date,   photo: buffer,   activity: string });  mongoose.model('event', eventschema); 

i use find method find other event documents around point user provides.

var maxdistance = 0.09; var lonlat = {$geometry: {type: 'point', coordinates: [34.09,124.34] }};  event.find({   'geo': {     $near: lonlat,     $maxdistance: maxdistance   } }).exec(function(err, events) {   if(err) {     throw err;   } else {     return events;   } }); 

what syntax have wrong here? missing huge? urls documentation great besides this link.

did try create index sentence?

db.event.ensureindex({ "location" : "2d" } )

it's little confusing example. don't if 'location' coordinates or 'geo', because create schema former , query latter.

in both cases, idea execute

db.event.findone().pretty()

so can check format of collection.

also command can check current indexes.

db.event.getindexes()

all of works if working on 'event' collection.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -