|
Hello! Thank you for filing this report.
That error is comes from attempting to decode a string as a primitive.ObjectID type using the default ObjectID decoder.
I can reproduce this error by inserting the document: {_id: "info"} into the collection "test.test" and running the following:
package main
|
|
import (
|
"context"
|
"fmt"
|
"log"
|
|
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
"go.mongodb.org/mongo-driver/mongo"
|
"go.mongodb.org/mongo-driver/mongo/options"
|
)
|
|
type MyStruct struct {
|
ID primitive.ObjectID `bson:"_id"`
|
}
|
|
func main() {
|
client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI("mongodb://localhost:27017"))
|
if err != nil {
|
fmt.Println(err)
|
return
|
}
|
|
matchStage := bson.D{{"$match", bson.D{}}}
|
cursor, err := client.Database("test").Collection("test").Aggregate(context.TODO(), mongo.Pipeline{matchStage})
|
if err != nil {
|
log.Fatalf("aggregate error: %v", err)
|
}
|
|
if !cursor.Next(context.TODO()) {
|
log.Fatalf("no results")
|
}
|
|
res := &MyStruct{}
|
err = cursor.Decode(&res)
|
if err != nil {
|
log.Fatalf("decode error: %v", err)
|
}
|
}
|
Can you provide additional details on how you are attempting to decode the documents returned from the Cursor returned by Aggregate? If possible a short, self-contained, compilable example showing your issue would be helpful.
|