mongo

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

MongoDB Library

package mongoexample

import (
	"context"

	"clodeo.tech/platform/go-universe/pkg/mongo"
	"go.mongodb.org/mongo-driver/bson"
)

func ConnectMongoExample() {
	mongodb = mongo.MongoConnectClient(&mongo.Client{
		URI:            "mongodb://localhost:27017",
		DB:             "test",
		AppName:        "test",
		ConnectTimeout: time.Duration(10) * time.Second,
		PingTimeout:    time.Duration(2) * time.Second,
	})

	// query exec example
	collection := mongodb.Database.Collection("test")
	result, err := collection.InsertOne(context.Background(), bson.M{"data": "value"})
	cursor, err := collection.Find(context.Background(), bson.M{})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	URI            string
	DB             string
	AppName        string
	ConnectTimeout time.Duration
	PingTimeout    time.Duration
	RetryWrites    bool
	ReadPrefMode   readpref.Mode
}

func (*Client) MongoConnect

func (c *Client) MongoConnect() (mc *driver.Client, err error)

type Database

type Database struct {
	Database *driver.Database
}

func MongoConnectClient

func MongoConnectClient(c *Client) *Database

Jump to

Keyboard shortcuts

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