mongodb

package module
v0.0.0-...-a3487a5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2022 License: MIT Imports: 8 Imported by: 0

README

MongoDB

PkgGoDev goreport

Environment Variables

MONGODB_DATABASE: Database name
MONGODB_URI:      Connection URI

Documentation

Overview

Package mongodb provides a mongodb fx module.

import "github.com/lucaskatayama/fx-contrib/mongodb"
Example

This is a simple usage of mongodb.Module with fx

package main

import (
	"go.uber.org/fx"

	"github.com/lucaskatayama/fx-contrib/mongodb"
)

func main() {
	// export MONGODB_DATABASE=db
	app := fx.New(
		mongodb.Module,
	)
	app.Run()
}
Output:

Example (Example1)

Setting MONGODB_URI

package main

import (
	"go.uber.org/fx"

	"github.com/lucaskatayama/fx-contrib/mongodb"
)

func main() {
	// export MONGODB_URI=mongodb://localhost:27017
	app := fx.New(
		mongodb.Module,
	)
	app.Run()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrDBNameRequired is returned when MONGODB_DATABASE name is not defined on environment variables
	ErrDBNameRequired = errors.New("MONGODB_DATABASE is required")
)
View Source
var Module = fx.Options(
	fx.Provide(new),
	fx.Provide(newDatabase),
	fx.Provide(check),
	fx.Invoke(lifecycle),
)

Module defines a mongodb module for fx.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL