1 回答

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個贊
終于找到了問題..實(shí)際上,我沒有以正確的方式創(chuàng)建索引..
// 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
}
在索引聲明中,我有以下行:
pIndex := mgo.Index{
Key: []string{"location:2dsphere"},
Bits: 26,
}
但正確的寫法是
pIndex := mgo.Index{
Key: []string{"$2dsphere:location"},
Bits: 26,
}
希望能幫助到你 !
- 1 回答
- 0 關(guān)注
- 119 瀏覽
添加回答
舉報