mgo

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 9 Imported by: 0

README

mgo

Mgo is based on the official library mongo.


Example of use

    import "github.com/zhufuyi/sponge/pkg/mgo"

    // connect mongodb
    db, err := mgo.Init("mongodb://root:123456@192.168.3.37:27017/account")

    // close mongodb
    defer Close(db)

Documentation

Overview

Package mgo is a library wrapped on go.mongodb.org/mongo-driver/mongo, with added features paging queries, etc.

Index

Constants

View Source
const (
	// DBDriverName mongodb driver
	DBDriverName = "mongodb"
)

Variables

This section is empty.

Functions

func Close

func Close(db *mongo.Database) error

Close mongodb

func ConvertToObjectIDs

func ConvertToObjectIDs(ids []string) []primitive.ObjectID

ConvertToObjectIDs convert ids to objectIDs

func EmbedDeletedAt

func EmbedDeletedAt(update bson.M) bson.M

EmbedDeletedAt embed deleted_at datetime column

func EmbedUpdatedAt

func EmbedUpdatedAt(update bson.M) bson.M

EmbedUpdatedAt embed updated_at datetime column

func ExcludeDeleted

func ExcludeDeleted(filter bson.M) bson.M

ExcludeDeleted exclude soft deleted records

func Init

func Init(dsn string, opts ...*options.ClientOptions) (*mongo.Database, error)

Init connecting to mongo

func Init2

func Init2(uri string, dbName string, opts ...*options.ClientOptions) (*mongo.Database, error)

Init2 connecting to mongo using uri

Types

type Model

type Model struct {
	ID        primitive.ObjectID `bson:"_id" json:"id"`
	CreatedAt time.Time          `bson:"created_at" json:"createdAt"`
	UpdatedAt time.Time          `bson:"updated_at" json:"updatedAt"`
	DeletedAt *time.Time         `bson:"deleted_at,omitempty" json:"deletedAt,omitempty"`
}

Model embedded structs, add `bson: ",inline"` when defining table structs

func (*Model) SetModelValue

func (p *Model) SetModelValue()

SetModelValue set model fields

Directories

Path Synopsis
Package query is a library of custom condition queries, support for complex conditional paging queries.
Package query is a library of custom condition queries, support for complex conditional paging queries.

Jump to

Keyboard shortcuts

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