mongo

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMongoNoDoc = errors.New("mongo: no document results")

ErrMongoNoDoc is mongo: no document results

Functions

This section is empty.

Types

type BulkWriteResult

type BulkWriteResult = mongo.BulkWriteResult

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

Collection mongo-driver collection

func C

func C(collection string) *Collection

C Collection alias

func (*Collection) Aggregate

func (c *Collection) Aggregate(pipeline any, results any, opts ...*options.AggregateOptions) error

Aggregate performs an aggregation pipeline.

func (*Collection) FindByID

func (c *Collection) FindByID(id primitive.ObjectID, result any) error

FindByID finds a single document by id.

func (*Collection) Index

func (c *Collection) Index(keys ...bson.M) ([]string, error)

Index creates an index with the given keys and options.

func (*Collection) Insert

func (c *Collection) Insert(doc any, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

InsertWithResult inserts a single document into the collection and returns insert one result.

func (*Collection) InsertAll

func (c *Collection) InsertAll(docs []any, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertAllWithResult inserts the provided documents and returns insert many result.

func (*Collection) Where

func (c *Collection) Where(filter bson.D) *Session

Where finds docs by given filter

type CollectionSpecification

type CollectionSpecification = mongo.CollectionSpecification

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database mongo-driver database

func (*Database) C

func (d *Database) C(collection string) *Collection

C returns collection.

func (*Database) Collection

func (d *Database) Collection(collection string) *Collection

Collection returns collection.

func (*Database) CollectionNames

func (d *Database) CollectionNames() ([]string, error)

CollectionNames returns the collection names present in database.

type DatabaseSpecification

type DatabaseSpecification = mongo.DatabaseSpecification

type DeleteResult

type DeleteResult = mongo.DeleteResult

type IndexSpecification

type IndexSpecification = mongo.IndexSpecification

type InsertManyResult

type InsertManyResult = mongo.InsertManyResult

type InsertOneResult

type InsertOneResult = mongo.InsertOneResult

type ListDatabasesResult

type ListDatabasesResult = mongo.ListDatabasesResult

type Pipeline

type Pipeline = mongo.Pipeline

type RewrapManyDataKeyResult

type RewrapManyDataKeyResult = mongo.RewrapManyDataKeyResult

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session mongo session

func Get

func Get(uri ...string) *Session

single mode for session

func New

func New(uri ...string) *Session

New session

Relevant documentation:

https://docs.mongodb.com/manual/reference/connection-string/

func (*Session) C

func (s *Session) C(collection string) *Collection

C Collection alias

func (*Session) Client

func (s *Session) Client() *mongo.Client

Client return mongo Client

func (*Session) Collection

func (s *Session) Collection(collection string) *Collection

Collection returns collection

func (*Session) Connect

func (s *Session) Connect() error

Connect mongo client

func (*Session) Count

func (s *Session) Count(opts ...*options.CountOptions) int64

Count gets the number of documents matching the filter.

func (*Session) DB

func (s *Session) DB(db string) *Database

DB returns a value representing the named database.

func (*Session) FetchAll

func (s *Session) FetchAll(results any) error

FetchAll find all

func (*Session) Find

func (s *Session) Find(result any) error

Find returns up to one document that matches the model.

func (*Session) Pagination

func (s *Session) Pagination(page, limit int, results any) (int64, error)

Pagination pagination

func (*Session) Ping

func (s *Session) Ping() error

Ping verifies that the client can connect to the topology. If readPreference is nil then will use the client's default read preference.

func (*Session) Remove

func (s *Session) Remove(opts ...*options.DeleteOptions) error

Remove

func (*Session) RemoveID

func (s *Session) RemoveID(id primitive.ObjectID, opts ...*options.DeleteOptions) error

Remove by ID

func (*Session) RemoveOne

func (s *Session) RemoveOne(opts ...*options.DeleteOptions) error

Remove one

func (*Session) Run

func (s *Session) Run(size int32, callback func(*mongo.Cursor)) error

Run runs the given model.

func (*Session) SetOpts

func (s *Session) SetOpts(opts ...*options.FindOptions) *Session

SetOpts set find options

func (*Session) Update

func (s *Session) Update(update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

Update all

func (*Session) UpdateID

func (s *Session) UpdateID(id primitive.ObjectID, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

Update by id

func (*Session) UpdateOne

func (s *Session) UpdateOne(update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

Update one

type UpdateResult

type UpdateResult = mongo.UpdateResult

Jump to

Keyboard shortcuts

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