-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't panic on indexed int64 fields #23
Changes from 5 commits
40554f1
bdf2017
f46e270
7fa7b59
3cfd324
74bdb34
dfde865
60475b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1611,12 +1611,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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't checked the call site, but is downcasting int64 to in really necessary ? Mongo itself does handle 64bit integers IIRC. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For compatibility on 32 bit architectures I assume.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at the code properly, the only valid values are "1" and "-1" so casting isn't an issue. |
||
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 | ||
|
@@ -1625,10 +1638,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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/detials/details/