首页 > 连接mongodb,查询地理位置的问题

连接mongodb,查询地理位置的问题

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" } )
创建相应的索引。
还是无法正常工作。


db.PostCo.ensureIndex({"location":"2d"},{min:0,max:200})试试。


db.PostCo.ensureIndex( { location : "2dsphere" } )

mongodb,2d搜索,我记得好像是这么创建索引的,看你的错误是在java中用的第三方包报错了?在mongodb命令行中查询正常吗?

【热门文章】
【热门文章】