Skip to content

Instantly share code, notes, and snippets.

@ilmsg
Forked from Ice3man543/main.go
Created November 5, 2023 05:03
Show Gist options
  • Save ilmsg/dba3a307e9b27b2d15ac409f3a2d83a7 to your computer and use it in GitHub Desktop.
Save ilmsg/dba3a307e9b27b2d15ac409f3a2d83a7 to your computer and use it in GitHub Desktop.

Revisions

  1. @Ice3man543 Ice3man543 created this gist Apr 8, 2021.
    28 changes: 28 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    package main

    import (
    "context"
    "time"

    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
    "go.mongodb.org/mongo-driver/mongo/readpref"
    )

    func main() {
    ctx := context.Background()

    client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://127.0.0.1:27017"))
    if err != nil {
    panic(err)
    }
    defer func() {
    if err = client.Disconnect(ctx); err != nil {
    panic(err)
    }
    }()
    err = client.Ping(ctx, readpref.Primary())
    if err != nil {
    panic(err)
    }
    }