mongo

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 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 added in v0.1.1

func C(collection string) *Collection

C Collection alias

func (*Collection) Aggregate

func (c *Collection) Aggregate(pipeline interface{}, results interface{}, opts ...*options.AggregateOptions) error

Aggregate performs an aggregation pipeline.

func (*Collection) Count

func (c *Collection) Count(filter bson.D, opts ...*options.CountOptions) int64

Count gets the number of documents matching the filter.

func (*Collection) FindByID

func (c *Collection) FindByID(id primitive.ObjectID, result interface{}) 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 interface{}, 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 []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

InsertAllWithResult inserts the provided documents and returns insert many result.

func (*Collection) Remove

func (c *Collection) Remove(filter bson.D, opts ...*options.DeleteOptions) error

Remove deletes a single document from the collection.

func (*Collection) RemoveAll

func (c *Collection) RemoveAll(filter bson.D, opts ...*options.DeleteOptions) error

RemoveAll deletes multiple documents from the collection.

func (*Collection) RemoveID

func (c *Collection) RemoveID(id primitive.ObjectID, opts ...*options.DeleteOptions) error

RemoveID deletes a single document from the collection by id.

func (*Collection) Update

func (c *Collection) Update(filter bson.D, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateWithResult updates a single document in the collection and returns update result.

func (*Collection) UpdateAll

func (c *Collection) UpdateAll(filter bson.D, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateAll updates multiple documents in the collection.

func (*Collection) UpdateByID

func (c *Collection) UpdateByID(id primitive.ObjectID, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

UpdateByID updates a single document in the collection by id

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 added in v0.1.1

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) DB

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

DB returns a value representing the named database.

func (*Session) FetchAll

func (s *Session) FetchAll(results interface{}) error

FetchAll find all

func (*Session) Find

func (s *Session) Find(result interface{}) error

Find returns up to one document that matches the model.

func (*Session) Pagination

func (s *Session) Pagination(page, limit int, results interface{}) (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) 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

type UpdateResult

type UpdateResult = mongo.UpdateResult

Jump to

Keyboard shortcuts

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