[GODRIVER-2254] when use $in []uint8 query in go , will get (BadValue) $in needs an array Created: 13/Dec/21 Updated: 27/Oct/23 Resolved: 19/Jan/22 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | CRUD |
| Affects Version/s: | 1.8.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | sink smell | Assignee: | Benji Rewis (Inactive) |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | Bug, driver | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryWhen using the go mongodb driver, $in query, the (BadValue) $in needs an array error occurs if [] uint8 is used for the query. bug may be ? Our business has been affected. mongo-driver v1.8.1 mongodb instance is a shard cluster
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).How to Reproduce
Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example. Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by PM Bot [ 19/Jan/22 ] | ||
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. | ||
| Comment by Benji Rewis (Inactive) [ 04/Jan/22 ] | ||
|
Apologies for the delay sinksmell@163.com; we were off for the holidays. I don't think we can actually distinguish between a []uint8 and a []byte in the Go driver since they are type-aliased. See this example in the Go playground for why type assertions/casts fail to work as expected here. Did the workaround I suggested (using either bson.A in your FindOne filter or an array of a different integer type) work? Let me know. | ||
| Comment by Benji Rewis (Inactive) [ 15/Dec/21 ] | ||
|
Hello sinksmell@163.com! Thanks again for your report. This is indeed odd behavior, and I believe our BSON library is interpreting {{[]uint8 {1, 2, 3}}} as a byte slice (since the byte type is an alias for uint8 in Golang) instead of an actual array of numbers. You should be able to use
filter := bson.M{"type": bson.M{"$in": bson.A{1, 2, 3} }}
As your filter and get the correct behavior, but I understand that might be inconvenient.
I'll continue to investigate. | ||
| Comment by Benji Rewis (Inactive) [ 14/Dec/21 ] | ||
|
Thanks for your bug report, sinksmell@163.com! We're taking a look now. | ||
| Comment by sink smell [ 14/Dec/21 ] | ||
|
use "go.mongodb.org/mongo-driver/bson" also occurs ``` (BadValue) $in needs an array``` |