Last active
October 17, 2024 16:08
-
-
Save prestonvasquez/3f423aa2dd2ad0031320fbaccc2f135b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"go.mongodb.org/mongo-driver/bson" | |
"go.mongodb.org/mongo-driver/mongo" | |
) | |
func main() { | |
client, err := mongo.Connect(context.Background()) | |
if err != nil { | |
panic(err) | |
} | |
defer func() { client.Disconnect(context.Background()) }() | |
coll := client.Database("db").Collection("coll") | |
docs := make([]any, 1_000) | |
for i := range docs { | |
docs[i] = bson.D{{"x", i}} | |
} | |
docs = append(docs, bson.D{{"y", string(make([]byte, 17_000_000))}}) | |
_, err = coll.InsertMany(context.Background(), docs) | |
if err != nil { | |
log.Println("err: ", err) | |
} | |
cur, err := coll.Find(context.Background(), bson.D{}) | |
if err != nil { | |
log.Fatalf("failed to execute find command: %v", err) | |
} | |
var found []bson.D | |
if err := cur.All(context.Background(), &found); err != nil { | |
log.Fatalf("failed to decode data: %v", err) | |
} | |
fmt.Println("found: ", found) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment