mongo

package
v0.0.0-...-e9fe98c Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: MIT Imports: 5 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 {
	Close() error
	Database(string) DataLayer
}

Client interface describes a MongoDB client (a wrapper).

func NewMongoClient

func NewMongoClient(ctx context.Context, user string, pass string, host string, opts *mongo.ClientOptions) (Client, error)

NewMongoClient creates a new Wrapper.

type CollectionLayer

type CollectionLayer interface {
	InsertOne(ctx context.Context, document interface{}, opts ...option.InsertOneOptioner) (InsertOneResultLayer, error)
	FindOne(ctx context.Context, filter interface{}, opts ...option.FindOneOptioner) DocumentResultLayer
	FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...option.FindOneAndUpdateOptioner) DocumentResultLayer
	FindOneAndDelete(ctx context.Context, filter interface{}, opts ...option.FindOneAndDeleteOptioner) DocumentResultLayer
}

CollectionLayer abstracts the required functions for MongoDB.

type DataLayer

type DataLayer interface {
	Collection(name string) CollectionLayer
}

DataLayer wraps a CollectionLayer.

type DocumentResultLayer

type DocumentResultLayer interface {
	Decode() (*bson.Document, error)
}

DocumentResultLayer abstracts the Decode() method.

type InsertOneResultLayer

type InsertOneResultLayer interface{}

InsertOneResultLayer is an empty interface. No methods are required for this. Everything implements this.

type Wrapper

type Wrapper struct {
	*mongo.Client
	// contains filtered or unexported fields
}

Wrapper wraps the client. The client gets shadowed when tested.

func (Wrapper) Close

func (mc Wrapper) Close() error

Close closes the MongoDB connection.

func (Wrapper) Database

func (mc Wrapper) Database(name string) DataLayer

Database returns a Database object. DataLayer shadows the mongo.Database.

type WrapperCollection

type WrapperCollection struct {
	*mongo.Collection
}

WrapperCollection wraps mongo.Collection.

func (WrapperCollection) FindOne

func (c WrapperCollection) FindOne(ctx context.Context, filter interface{}, opts ...option.FindOneOptioner) DocumentResultLayer

FindOne finds a document given filters and options.

func (WrapperCollection) FindOneAndDelete

func (c WrapperCollection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...option.FindOneAndDeleteOptioner) DocumentResultLayer

FindOneAndDelete finds a document and removes it.

func (WrapperCollection) FindOneAndUpdate

func (c WrapperCollection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...option.FindOneAndUpdateOptioner) DocumentResultLayer

FindOneAndUpdate finds a document and updates it. Closest we have to a transaction.

func (WrapperCollection) InsertOne

func (c WrapperCollection) InsertOne(ctx context.Context, document interface{}, opts ...option.InsertOneOptioner) (InsertOneResultLayer, error)

InsertOne inserts a document.

type WrapperDatabase

type WrapperDatabase struct {
	*mongo.Database
}

WrapperDatabase wraps the mongo.Database.

func (WrapperDatabase) Collection

func (d WrapperDatabase) Collection(name string) CollectionLayer

Collection returns a mongo collection. CollectionLayer shadows the mongo.Collection.

type WrapperDocumentResult

type WrapperDocumentResult struct {
	*mongo.DocumentResult
}

WrapperDocumentResult wraps mongo.DocumentResult.

func (WrapperDocumentResult) Decode

func (d WrapperDocumentResult) Decode() (*bson.Document, error)

Decode decodes an element into a bson document. Note: Mongo's Decode() accepts a document as a parameter. This method uses Mongo's Decode(), but makes it simpler to test.

type WrapperInsertOneResult

type WrapperInsertOneResult struct {
	*mongo.InsertOneResult
}

WrapperInsertOneResult wraps mongo.InsertOneResult.

Jump to

Keyboard shortcuts

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