...

Source file src/go.mongodb.org/mongo-driver/cmd/testaws/main.go

Documentation: go.mongodb.org/mongo-driver/cmd/testaws

     1  // Copyright (C) MongoDB, Inc. 2017-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package main
     8  
     9  import (
    10  	"context"
    11  	"errors"
    12  	"fmt"
    13  	"os"
    14  
    15  	"go.mongodb.org/mongo-driver/bson"
    16  	"go.mongodb.org/mongo-driver/mongo"
    17  	"go.mongodb.org/mongo-driver/mongo/options"
    18  )
    19  
    20  func main() {
    21  	uri := os.Getenv("MONGODB_URI")
    22  	ctx := context.Background()
    23  
    24  	client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
    25  	if err != nil {
    26  		panic(fmt.Sprintf("Connect error: %v", err))
    27  	}
    28  
    29  	defer func() {
    30  		if err = client.Disconnect(ctx); err != nil {
    31  			panic(fmt.Sprintf("Disconnect error: %v", err))
    32  		}
    33  	}()
    34  
    35  	db := client.Database("aws")
    36  	coll := db.Collection("test")
    37  	if err = coll.FindOne(ctx, bson.D{{"x", 1}}).Err(); err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
    38  		panic(fmt.Sprintf("FindOne error: %v", err))
    39  	}
    40  }
    41  

View as plain text