Skip to content

Commit

Permalink
Also parse int64 when processing indexes (go-mgo#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
mapete94 authored and niemeyer committed Aug 7, 2017
1 parent 40554f1 commit ac340de
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1534,12 +1534,25 @@ func (idxs indexSlice) Swap(i, j int) { idxs[i], idxs[j] = idxs[j], idxs[i]

func simpleIndexKey(realKey bson.D) (key []string) {
for i := range realKey {
var vi int
field := realKey[i].Name
vi, ok := realKey[i].Value.(int)
if !ok {

switch realKey[i].Value.(type) {
case int64:
vf, _ := realKey[i].Value.(int64)
vi = int(vf)
case float64:
vf, _ := realKey[i].Value.(float64)
vi = int(vf)
case string:
if vs, ok := realKey[i].Value.(string); ok {
key = append(key, "$"+vs+":"+field)
continue
}
case int:
vi = realKey[i].Value.(int)
}

if vi == 1 {
key = append(key, field)
continue
Expand All @@ -1548,10 +1561,6 @@ func simpleIndexKey(realKey bson.D) (key []string) {
key = append(key, "-"+field)
continue
}
if vs, ok := realKey[i].Value.(string); ok {
key = append(key, "$"+vs+":"+field)
continue
}
panic("Got unknown index key type for field " + field)
}
return
Expand Down

0 comments on commit ac340de

Please sign in to comment.