Connect mongodb to inquire about geographical location

  mongodb, question

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(
at com.mongodb.QueryResultIterator.init(
at com.mongodb.QueryResultIterator.initFromQueryResponse(
at com.mongodb.QueryResultIterator.(
at com.mongodb.DBCollectionImpl.find(
at com.mongodb.DBCollectionImpl.find(
at com.mongodb.DBCursor._check(
at com.mongodb.DBCursor._hasNext(
at com.mongodb.DBCursor.hasNext(

I have already used
db.PostCo.createIndex( { location : “2dsphere” } )
db.PostCo.createIndex( { location : “2d” } )
Create the corresponding index.
Still can’t work normally.

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

Mongodb, 2d search, I remember that it seems to create an index like this. See if your error was reported by a third-party package used in java? Is it normal to query on the mongodb command line?