mongodb

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MODULE = "mongodb"

Variables

View Source
var ErrDisconnect = errors.New("数据库未连接")

Functions

func Aggregate

func Aggregate(tab string, pipeline any, results any) error

func BulkWrite

func BulkWrite(tab string, models []mongo.WriteModel) (*mongo.BulkWriteResult, error)

func Close

func Close() error

func Count

func Count(tab string, filter any) (count int64, err error)

func CreateIndex

func CreateIndex(tab string, keys []string) error

func CreateTable

func CreateTable(name string, opts *options.CreateCollectionOptions) error

func Database

func Database() (*mongo.Database, error)

func DeleteById

func DeleteById(tab string, id primitive.ObjectID) (int64, error)

func DeleteMany

func DeleteMany(tab string, filter any) (int64, error)

func DeleteOne

func DeleteOne(tab string, filter any) (int64, error)

func Distinct

func Distinct(tab string, filter any, field string) (values []any, err error)

func DistinctId

func DistinctId(tab string, filter any) (ids []primitive.ObjectID, err error)

func Download

func Download(filename string) (*gridfs.DownloadStream, error)

func DownloadById

func DownloadById(id primitive.ObjectID) (*gridfs.DownloadStream, error)

func DownloadTo

func DownloadTo(filename string, writer io.Writer) (int64, error)

func DownloadToById

func DownloadToById(id primitive.ObjectID, writer io.Writer) (int64, error)

func Drop

func Drop(tab string) error

func Find

func Find(tab string, filter any, sort any, skip int64, limit int64, results any) error

func FindById

func FindById(tab string, id primitive.ObjectID, result any) (has bool, err error)

func FindFile

func FindFile(filter any, sort any, skip int32, limit int32, results any) error

func FindOne

func FindOne(tab string, filter any, result any) (has bool, err error)

func FindOneAndDelete

func FindOneAndDelete(tab string, filter any, raw any) (has bool, err error)

func FindOneAndReplace

func FindOneAndReplace(tab string, filter any, replace any, raw any) (has bool, err error)

func FindOneAndUpdate

func FindOneAndUpdate(tab string, filter any, update any, raw any) (has bool, err error)

func InsertMany

func InsertMany(tab string, docs []any) (ids []primitive.ObjectID, err error)

func InsertOne

func InsertOne(tab string, doc any) (id primitive.ObjectID, err error)

func Open

func Open() error

func ParseDocumentObjectId

func ParseDocumentObjectId(doc any)

func ParseObjectId

func ParseObjectId(id any) (primitive.ObjectID, error)

func Ping

func Ping() error

func Remove

func Remove(id primitive.ObjectID) error

func Rename

func Rename(id primitive.ObjectID, filename string) error

func ReplaceOne

func ReplaceOne(tab string, filter any, result any, upsert bool) (int64, error)

func StringifyDocumentObjectId

func StringifyDocumentObjectId(doc any)

func StringifyObjectId

func StringifyObjectId(id any) (string, error)

func Tables

func Tables() ([]string, error)

func UpdateById

func UpdateById(tab string, id primitive.ObjectID, update any, upsert bool) (int64, error)

func UpdateMany

func UpdateMany(tab string, filter any, update any, upsert bool) (int64, error)

func UpdateOne

func UpdateOne(tab string, filter any, update any, upsert bool) (int64, error)

func Upload

func Upload(filename string, metadata any) (*gridfs.UploadStream, error)

func UploadFrom

func UploadFrom(filename string, metadata any, reader io.Reader) (id primitive.ObjectID, err error)

Types

type Batch

type Batch struct {
	Collection   string
	WriteTimeout time.Duration
	BufferSize   int
	// contains filtered or unexported fields
}

func (*Batch) DeleteMany

func (b *Batch) DeleteMany(filter any)

func (*Batch) DeleteOne

func (b *Batch) DeleteOne(filter any)

func (*Batch) Flush

func (b *Batch) Flush() (*mongo.BulkWriteResult, error)

func (*Batch) InsertOne

func (b *Batch) InsertOne(doc any)

func (*Batch) UpdateMany

func (b *Batch) UpdateMany(filter any, update any, upsert bool)

func (*Batch) UpdateOne

func (b *Batch) UpdateOne(filter any, update any, upsert bool)

func (*Batch) Write

func (b *Batch) Write(model mongo.WriteModel)

type Document

type Document map[string]any

Jump to

Keyboard shortcuts

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