Closed Emixam23 closed 5 years ago
Hi @Emixam23
There's an experimental (read: unsupported) API for geospatial queries in the geospatial-geoNear branch - check these commits - maybe they can help you!
Dom
Hey !
Finally found the issue.. Actually, I wasn't creating the index in the right way..
// EnsureIndex force ids to be unique
func EnsureAddressIndex(session *mgo.Session) error {
_session := session.Copy()
defer _session.Close()
c := _session.DB(constants.DBName).C(addressDocument)
// Might be needed one day
pIndex := mgo.Index{
Key: []string{"$2dsphere:location"},
Bits: 26,
}
err := c.EnsureIndex(pIndex)
if err != nil {
return err
}
return nil
}
At the index declaration, I had the following line:
pIndex := mgo.Index{
Key: []string{"location:2dsphere"},
Bits: 26,
}
But the correct way to write it is
pIndex := mgo.Index{
Key: []string{"$2dsphere:location"},
Bits: 26,
}
Hope it helps !
Awesome! Thanks for reporting back 👍
Dom
Of course, you're welcome :) It perfectly works as far as I could see.
Max
Hey !
I am coming because I need to realize geocalculs, however, it doesn't work..
From the doc we have this:
Query a 2dsphere index : https://docs.mongodb.com/manual/tutorial/query-a-2dsphere-index/ 2dsphere Indexes : https://docs.mongodb.com/manual/core/2dsphere/
So I have the following:
From this, I got the following error:
I ensure my index at the initialization of my program
Any idea? I have more than 20k addresses and they all have lat/lng ... :(
Thanks !