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(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)

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?