During a unit test on MongoDB geo data query, I get the following error message:
can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { address.location: { $nearSphere: { x: -120.0, y: 47.0 }, $maxDistance: 0.01567855942887398 }, status: "INIT" }; nested exception is com.mongodb.MongoException: can't find any special indices: 2d (needs index), 2dsphere (needs index), for: { address.location: { $nearSphere: { x: -120.0, y: 47.0 }, $maxDistance: 0.01567855942887398 }, status: "INIT" }
After running the createIndex
command, I however, get the following errors:
db.store.createIndex({"address.location":"2d"}) location object expected, location array not in correct format db.store.createIndex({"address.location":"2dsphere"}) Can't extract geo keys from object, malformed geometry?:{ type: "Point", coordinates: [ 47.399465, -122.2950165 ] }
The structure of the document data is the followings:
{
....
"address" : {
"street" : "Street One",
"city" : "One City",
"province" : "aProvince",
"country" : "aCountry",
"postalCode" : "91202",
"location" : {
"type" : "Point",
"coordinates" : [
47.5891279,
-122.0446183
]
}
}
What I do it wrong?