Detailed steps to reproduce the problem?
Include full traceback, if possible
Reproducible with the following script:
package main import ( "bytes" "fmt" "io" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/bsonrw" ) func main() { ej := []byte(`[{"x":1},{"y":2}]`) rw, err := bsonrw.NewExtJSONValueReader(bytes.NewReader(ej), true) if err != nil { panic(err) } dec, err := bson.NewDecoder(rw) if err != nil { panic(err) } for { var data interface{} err := dec.Decode(&data) if err == io.EOF { break } if err != nil { panic(err) } fmt.Println("data: ", data) } }
Output:
❯ go run main.go
data: [[{x 1}] [{y 2}]]
panic: runtime error: index out of range [-2]
goroutine 1 [running]:
go.mongodb.org/mongo-driver/bson/bsonrw.(*extJSONValueReader).Type(0x14000143b98?)
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsonrw/extjson_reader.go:237 +0x48
go.mongodb.org/mongo-driver/bson/bsoncodec.EmptyInterfaceCodec.decodeType({0xa0?}, {0x1400013cc40, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, 0x0, ...}, ...)
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/empty_interface_codec.go:116 +0x1cc
go.mongodb.org/mongo-driver/bson/bsoncodec.EmptyInterfaceCodec.DecodeValue({0x74?}, {0x1400013cc40, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, 0x0, ...}, ...)
/Users/preston.vasquez/Developer/mongo-go-driver/bson/bsoncodec/empty_interface_codec.go:152 +0x178
go.mongodb.org/mongo-driver/bson.(*Decoder).Decode(0x14000143f18, {0x1043d6260?, 0x1400010bad0})
/Users/preston.vasquez/Developer/mongo-go-driver/bson/decoder.go:134 +0x3b4
main.main()
/Users/preston.vasquez/Developer/technical/workshop/mongo/bson/more/main.go:27 +0x1b4
exit status 2
Definition of done: what must be done to consider the task complete?
An io.Reader should return io.EOF when the stack is exhuasted.
The exact Go version used, with patch level:
go version go1.20.5 darwin/arm64
The exact version of the Go driver used:
go.mongodb.org/mongo-driver v1.11.4
Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.
local distro, 7.0.2 server version, replica set:
${DRIVERS_TOOLS}/.evergreen/start-orchestration.sh /Users/preston.vasquez/Developer/mongo-orchestration-home
curl -X POST http://localhost:8889/v1/replica_sets \ -H 'Content-Type: application/json' \ -d @${DRIVERS_TOOLS}/.evergreen/orchestration/configs/replica_sets/basic.json
The operating system and version (e.g. Windows 7, OSX 10.8, ...)
OSX ventura 13.6
Security Vulnerabilities
NA
- is related to
-
GODRIVER-2835 Support reading a stream of BSON documents with Decoder
-
- Closed
-
- related to
-
GODRIVER-3025 Create a peeking methodology for bson.Decode
-
- Backlog
-