rmongodb

package module
v0.0.0-...-b0d077b Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	Connect(ctx context.Context) (err error)
	Database(name string, opts ...*options.DatabaseOptions) (db Database)
	Disconnect(ctx context.Context) (err error)
	StartSession(opts ...*options.SessionOptions) (Session, error)
}

Client is a collection of behavior of mongodb client.

func NewClientAdapter

func NewClientAdapter(mongoClient *mongo.Client) Client

NewClientAdapter is a constructor.

type ClientAdapter

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

ClientAdapter is a concrete struct of mongodb client adapter.

func (*ClientAdapter) Connect

func (c *ClientAdapter) Connect(ctx context.Context) (err error)

Connect initializes the Client by starting background monitoring goroutines. If the Client was created using the NewClient function, this method must be called before a Client can be used.

Connect starts background goroutines to monitor the state of the deployment and does not do any I/O in the main goroutine. The Client.Ping method can be used to verify that the connection was created successfully.

func (*ClientAdapter) Database

func (c *ClientAdapter) Database(name string, opts ...*options.DatabaseOptions) (db Database)

Database returns a handle for a database with the given name configured with the given DatabaseOptions.

func (*ClientAdapter) Disconnect

func (c *ClientAdapter) Disconnect(ctx context.Context) (err error)

Disconnect closes sockets to the topology referenced by this Client. It will shut down any monitoring goroutines, close the idle connection pool, and will wait until all the in use connections have been returned to the connection pool and closed before returning. If the context expires via cancellation, deadline, or timeout before the in use connections have returned, the in use connections will be closed, resulting in the failure of any in flight read or write operations. If this method returns with no errors, all connections associated with this Client have been closed.

func (*ClientAdapter) StartSession

func (c *ClientAdapter) StartSession(opts ...*options.SessionOptions) (s Session, err error)

type Collection

type Collection interface {
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (result SingleResult)
	Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (cursor Cursor, err error)
	InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (result *mongo.InsertOneResult, err error)
	InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error)
	CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (counted int64, err error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (result *mongo.DeleteResult, err error)
	DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (result *mongo.DeleteResult, err error)
	UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)
	UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)
}

Collection is a collection of behavior of mongodb client.

type CollectionAdapter

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

CollectionAdapter is a concrete struct of mongodb collection adapter.

func (*CollectionAdapter) CountDocuments

func (col *CollectionAdapter) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (counted int64, err error)

CountDocuments returns the number of documents in the collection. For a fast count of the documents in the collection, see the EstimatedDocumentCount method.

The filter parameter must be a document and can be used to select which documents contribute to the count. It cannot be nil. An empty document (e.g. bson.D{}) should be used to count all documents in the collection. This will result in a full collection scan.

The opts parameter can be used to specify options for the operation (see the options.CountOptions documentation).

func (*CollectionAdapter) DeleteMany

func (col *CollectionAdapter) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (result *mongo.DeleteResult, err error)

DeleteMany executes a delete command to delete documents from the collection.

The filter parameter must be a document containing query operators and can be used to select the documents to be deleted. It cannot be nil. An empty document (e.g. bson.D{}) should be used to delete all documents in the collection. If the filter does not match any documents, the operation will succeed and a DeleteResult with a DeletedCount of 0 will be returned.

The opts parameter can be used to specify options for the operation (see the options.DeleteOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/delete/.

func (*CollectionAdapter) DeleteOne

func (col *CollectionAdapter) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (result *mongo.DeleteResult, err error)

DeleteOne executes a delete command to delete at most one document from the collection.

The filter parameter must be a document containing query operators and can be used to select the document to be deleted. It cannot be nil. If the filter does not match any documents, the operation will succeed and a DeleteResult with a DeletedCount of 0 will be returned. If the filter matches multiple documents, one will be selected from the matched set.

The opts parameter can be used to specify options for the operation (see the options.DeleteOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/delete/.

func (*CollectionAdapter) Find

func (col *CollectionAdapter) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (cursor Cursor, err error)

Find executes a find command and returns a Cursor over the matching documents in the collection.

The filter parameter must be a document containing query operators and can be used to select which documents are included in the result. It cannot be nil. An empty document (e.g. bson.D{}) should be used to include all documents.

The opts parameter can be used to specify options for the operation (see the options.FindOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/find/.

func (*CollectionAdapter) FindOne

func (col *CollectionAdapter) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (result SingleResult)

FindOne executes a find command and returns a SingleResult for one document in the collection.

The filter parameter must be a document containing query operators and can be used to select the document to be returned. It cannot be nil. If the filter does not match any documents, a SingleResult with an error set to ErrNoDocuments will be returned. If the filter matches multiple documents, one will be selected from the matched set.

The opts parameter can be used to specify options for this operation (see the options.FindOneOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/find/.

func (*CollectionAdapter) InsertMany

func (col *CollectionAdapter) InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error)

InsertMany executes an insert command to insert multiple documents into the collection. If write errors occur during the operation (e.g. duplicate key error), this method returns a BulkWriteException error.

The documents parameter must be a slice of documents to insert. The slice cannot be nil or empty. The elements must all be non-nil. For any document that does not have an _id field when transformed into BSON, one will be added automatically to the marshalled document. The original document will not be modified. The _id values for the inserted documents can be retrieved from the InsertedIDs field of the returnd InsertManyResult.

The opts parameter can be used to specify options for the operation (see the options.InsertManyOptions documentation.)

For more information about the command, see https://docs.mongodb.com/manual/reference/command/insert/.

func (*CollectionAdapter) InsertOne

func (col *CollectionAdapter) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (result *mongo.InsertOneResult, err error)

InsertOne executes an insert command to insert a single document into the collection.

The document parameter must be the document to be inserted. It cannot be nil. If the document does not have an _id field when transformed into BSON, one will be added automatically to the marshalled document. The original document will not be modified. The _id can be retrieved from the InsertedID field of the returned InsertOneResult.

The opts parameter can be used to specify options for the operation (see the options.InsertOneOptions documentation.)

For more information about the command, see https://docs.mongodb.com/manual/reference/command/insert/.

func (*CollectionAdapter) UpdateMany

func (col *CollectionAdapter) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)

UpdateMany executes an update command to update documents in the collection.

The filter parameter must be a document containing query operators and can be used to select the documents to be updated. It cannot be nil. If the filter does not match any documents, the operation will succeed and an UpdateResult with a MatchedCount of 0 will be returned.

The update parameter must be a document containing update operators (https://docs.mongodb.com/manual/reference/operator/update/) and can be used to specify the modifications to be made to the selected documents. It cannot be nil or empty.

The opts parameter can be used to specify options for the operation (see the options.UpdateOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/update/.

func (*CollectionAdapter) UpdateOne

func (col *CollectionAdapter) UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (result *mongo.UpdateResult, err error)

UpdateOne executes an update command to update at most one document in the collection.

The filter parameter must be a document containing query operators and can be used to select the document to be updated. It cannot be nil. If the filter does not match any documents, the operation will succeed and an UpdateResult with a MatchedCount of 0 will be returned. If the filter matches multiple documents, one will be selected from the matched set and MatchedCount will equal 1.

The update parameter must be a document containing update operators (https://docs.mongodb.com/manual/reference/operator/update/) and can be used to specify the modifications to be made to the selected document. It cannot be nil or empty.

The opts parameter can be used to specify options for the operation (see the options.UpdateOptions documentation).

For more information about the command, see https://docs.mongodb.com/manual/reference/command/update/.

type Cursor

type Cursor interface {
	ID() int64
	Next(ctx context.Context) bool
	Decode(val interface{}) error
	Close(ctx context.Context) error
}

Cursor is a collection of function of mongodb cursor.

type Database

type Database interface {
	Collection(name string, opts ...*options.CollectionOptions) (col Collection)
}

Database is a collection of behavior of mongodb database.

type DatabaseAdapter

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

DatabaseAdapter is concrete struct of mongodb database adapter.

func (*DatabaseAdapter) Collection

func (db *DatabaseAdapter) Collection(name string, opts ...*options.CollectionOptions) (col Collection)

Collection gets a handle for a collection with the given name configured with the given CollectionOptions.

type Session

type Session interface {
	StartTransaction(...*options.TransactionOptions) (err error)
	AbortTransaction(context.Context) (err error)
	CommitTransaction(context.Context) (err error)
	WithTransaction(ctx context.Context, fn func(sessCtx mongo.SessionContext) (interface{}, error),
		opts ...*options.TransactionOptions) (it interface{}, err error)
	EndSession(context.Context)
	ID() (r bson.Raw)
}

type SessionAdapter

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

func (*SessionAdapter) AbortTransaction

func (s *SessionAdapter) AbortTransaction(ctx context.Context) (err error)

func (*SessionAdapter) CommitTransaction

func (s *SessionAdapter) CommitTransaction(ctx context.Context) (err error)

func (*SessionAdapter) EndSession

func (s *SessionAdapter) EndSession(ctx context.Context)

func (*SessionAdapter) ID

func (s *SessionAdapter) ID() (r bson.Raw)

func (*SessionAdapter) StartTransaction

func (s *SessionAdapter) StartTransaction(opts ...*options.TransactionOptions) (err error)

func (*SessionAdapter) WithTransaction

func (s *SessionAdapter) WithTransaction(ctx context.Context, fn func(sessCtx mongo.SessionContext) (interface{}, error),
	opts ...*options.TransactionOptions) (it interface{}, err error)

type SingleResult

type SingleResult interface {
	Decode(v interface{}) error
	Err() error
}

SingleResult is a collectioin of function of mongodb single result.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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