INNER CODE UNIT · Go
getCollection
chenmingyong0423/go-mongox · collection_e2e_test.go:66
func getCollection[T any](t *testing.T) *Collection[T] {
client, err := mongo.Connect(options.Client().ApplyURI("mongodb://localhost:27017").SetAuth(options.Credential{
Username: "test",
Password: "test",
AuthSource: "db-test",
}))
assert.NoError(t, err)
assert.NoError(t, client.Ping(context.Background(), readpref.Primary()))
collection := NewCollection[T](NewClient(client, &Config{}).NewDatabase("db-test"), "test_user")
return collection
}