mongodb

package module
v0.30.9 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 4

README

data-mongo

GoDoc Version Build Status Go Report Card Codecov

Mongodb adapter for the "data" interface

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpressionToBSON

func ExpressionToBSON(criteria exp.Expression) bson.M

ExpressionToBSON converts a data.Expression value into pure bson.

func SetLogTimeout added in v0.30.2

func SetLogTimeout(timeout int)

Types

type Collection

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

Collection wraps a mongodb.Collection with all of the methods required by the data.Collection interface

func NewCollection added in v0.28.3

func NewCollection(collection *mongo.Collection) Collection

NewCollection creates a new Collection object directly from a mongo.Collection

func (Collection) Context added in v0.30.4

func (c Collection) Context() context.Context

func (Collection) Count added in v0.28.0

func (c Collection) Count(criteria exp.Expression, _ ...option.Option) (int64, error)

func (Collection) Delete

func (c Collection) Delete(object data.Object, note string) error

Delete removes a single object from the database, using a "virtual delete"

func (Collection) HardDelete added in v0.1.0

func (c Collection) HardDelete(criteria exp.Expression) error

HardDelete physically removes an object from the database.

func (Collection) Iterator added in v0.28.0

func (c Collection) Iterator(criteria exp.Expression, options ...option.Option) (data.Iterator, error)

Iterator retrieves a group of objects from the database as an iterator

func (Collection) Load

func (c Collection) Load(criteria exp.Expression, target data.Object, options ...option.Option) error

Load retrieves a single object from the database

func (Collection) Mongo

func (c Collection) Mongo() *mongo.Collection

Mongo returns the underlying mongodb collection for libraries that need to bypass this abstraction.

func (Collection) Query added in v0.2.2

func (c Collection) Query(target any, criteria exp.Expression, options ...option.Option) error

Query retrieves a group of objects from the database and populates a target interface

func (Collection) Save

func (c Collection) Save(object data.Object, note string) error

Save inserts/updates a single object in the database.

type GeoJSONer added in v0.30.8

type GeoJSONer interface {

	// GeoJSON returns a GeoJSON representation of a geometric shape.
	GeoJSON() map[string]any
}

GeoJSONer interface wraps the GeoJSON method, which generates a GeoJSON object for a given dataset

type Iterator

type Iterator struct {
	Context context.Context
	Cursor  *mongo.Cursor
}

Iterator wraps the mongodb Cursor object

func NewIterator

func NewIterator(context context.Context, cursor *mongo.Cursor) Iterator

NewIterator returns a fully populated Iterator object

func (Iterator) Close

func (iterator Iterator) Close() error

Close closes the wrapped Cursor

func (Iterator) Count

func (iterator Iterator) Count() int

Count returns the total number of records contained by this iterator

func (Iterator) Error added in v0.21.0

func (iterator Iterator) Error() error

func (Iterator) Next

func (iterator Iterator) Next(output any) bool

Next populates the next value from the wrapped Cursor, or returns FALSE

type Server

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

Server is an abstract representation of a MongoDB database. It implements the data.Server interface, so that it should be usable anywhere that requires a data.Server.

func New

func New(uri string, database string, opt *options.ClientOptions) (Server, error)

New returns a fully populated mongodb.Server. It requires that you provide the URI for the mongodb cluster, along with the name of the database to be used for all transactions.

func NewServer added in v0.30.4

func NewServer(database *mongo.Database) Server

func (Server) Client added in v0.30.4

func (server Server) Client() *mongo.Client

Mongo returns the underlying mongodb client for libraries that need to bypass this abstraction.

func (Server) Database added in v0.30.4

func (server Server) Database() *mongo.Database

func (Server) Session

func (server Server) Session(ctx context.Context) (data.Session, error)

Session returns a new client session that can be used to perform CRUD transactions on this datastore.

func (Server) WithTransaction added in v0.30.4

func (server Server) WithTransaction(ctx context.Context, fn data.TransactionCallbackFunc) (any, error)

type Session

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

Session represents a single database session, such as a session encompassing all of the database queries to respond to a single REST service call.

func NewSession added in v0.28.3

func NewSession(database *mongo.Database) Session

NewSession generates a new Session object from a mongo.Database

func (Session) Close

func (s Session) Close()

Close cleans up any remaining connections that need to be removed.

func (Session) Collection

func (s Session) Collection(collection string) data.Collection

Collection returns a reference to an individual database collection.

func (Session) Context added in v0.30.4

func (s Session) Context() context.Context

Context returns the context associated with this session.

func (Session) Mongo

func (s Session) Mongo() *mongo.Database

Mongo returns the underlying mongodb client for libraries that need to bypass this abstraction.

Jump to

Keyboard shortcuts

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