-
-
Save divjotarora/f0b5b82433deefbbf6ead8f7e57e6b43 to your computer and use it in GitHub Desktop.
Go Driver bsoncore.Array pipeline repro
This file contains 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" | |
"go.mongodb.org/mongo-driver/mongo" | |
"go.mongodb.org/mongo-driver/mongo/options" | |
"go.mongodb.org/mongo-driver/x/bsonx/bsoncore" | |
) | |
const ( | |
uri = "mongodb://localhost:27017/?serverSelectionTimeoutMS=1000" | |
) | |
var ( | |
ctx = context.TODO() | |
) | |
func main() { | |
client := setupClient() | |
defer client.Disconnect(ctx) | |
coll := client.Database("foo").Collection("bar") | |
if err := coll.Drop(ctx); err != nil { | |
panic(err) | |
} | |
// {"$match": {}} | |
stage := bsoncore.NewDocumentBuilder(). | |
StartDocument("$match"). | |
FinishDocument(). | |
Build() | |
pipeline := bsoncore.NewArrayBuilder().AppendDocument(stage).Build() | |
if _, err := coll.Aggregate(ctx, pipeline); err != nil { | |
panic(err) | |
} | |
} | |
func setupClient() *mongo.Client { | |
opts := options.Client().ApplyURI(uri) | |
client, err := mongo.Connect(ctx, opts) | |
if err != nil { | |
panic(err) | |
} | |
return client | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment