com.mongodb.MongoException: can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { position: { $nearSphere: [ 120.344944, 36.067463 ] } }
at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:214)
at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198)
at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176)
at com.mongodb.QueryResultIterator.(QueryResultIterator.java:64)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:86)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBCursor._check(DBCursor.java:458)
at com.mongodb.DBCursor._hasNext(DBCursor.java:546)
at com.mongodb.DBCursor.hasNext(DBCursor.java:571)
我已经利用
db.PostCo.createIndex( { location : "2dsphere" } )
db.PostCo.createIndex( { location : "2d" } )
创建相应的索引。
还是无法正常工作。
Mongodb, 2D search, I remember that the index seems to be created like this. It seems that your error is reported by the third-party package used in Java? Is it normal to query in mongodb command line?
db.PostCo.ensureIndex({"location":"2d"},{min:0,max:200}) try.
It is recommended to use https://github.com/T-baby/Mon..., you can refer to the document https://t-baby.gitbooks.io/mo... to implement geographical location query, MongoDB-Plugin simplifies it Native writing method, so you can get started after reading it once