连接mongodb,查询地理位置的问题
巴扎黑
巴扎黑 2017-04-25 09:03:38
0
3
774

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

巴扎黑
巴扎黑

reply all(3)
黄舟
db.PostCo.ensureIndex( { location : "2dsphere" } )

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?

PHPzhong

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template