db: github.com/upper/db/adapter/mongo Index | Files

package mongo

import "github.com/upper/db/adapter/mongo"

Package mongo wraps the gopkg.in/mgo.v2 MongoDB driver. See https://github.com/upper/db/adapter/mongo for documentation, particularities and usage examples.


Package Files

collection.go connection.go database.go result.go


const Adapter = `mongo`

Adapter holds the name of the mongodb adapter.

func Open Uses

func Open(settings db.ConnectionURL) (db.Session, error)

Open stablishes a new connection to a SQL server.

type Collection Uses

type Collection struct {
    // contains filtered or unexported fields

Collection represents a mongodb collection.

func (*Collection) Count Uses

func (col *Collection) Count() (uint64, error)

func (*Collection) Exists Uses

func (col *Collection) Exists() (bool, error)

Exists returns true if the collection exists.

func (*Collection) Find Uses

func (col *Collection) Find(terms ...interface{}) db.Result

Find creates a result set with the given conditions.

func (*Collection) Insert Uses

func (col *Collection) Insert(item interface{}) (db.InsertResult, error)

Insert inserts a record (map or struct) into the collection.

func (*Collection) InsertReturning Uses

func (col *Collection) InsertReturning(item interface{}) error

func (*Collection) Name Uses

func (col *Collection) Name() string

Name returns the name of the table or tables that form the collection.

func (*Collection) Session Uses

func (col *Collection) Session() db.Session

func (*Collection) Truncate Uses

func (col *Collection) Truncate() error

Truncate deletes all rows from the table.

func (*Collection) UpdateReturning Uses

func (col *Collection) UpdateReturning(item interface{}) error

type ConnectionURL Uses

type ConnectionURL struct {
    User     string
    Password string
    Host     string
    Database string
    Options  map[string]string

ConnectionURL implements a MongoDB connection struct.

func ParseURL Uses

func ParseURL(s string) (conn ConnectionURL, err error)

ParseURL parses s into a ConnectionURL struct.

func (ConnectionURL) String Uses

func (c ConnectionURL) String() (s string)

type Source Uses

type Source struct {
    // contains filtered or unexported fields

Source represents a MongoDB database.

func (*Source) Clone Uses

func (s *Source) Clone() (db.Session, error)

Clone returns a cloned db.Session session.

func (*Source) Close Uses

func (s *Source) Close() error

Close terminates the current database session.

func (*Source) Collection Uses

func (s *Source) Collection(name string) db.Collection

Collection returns a collection by name.

func (*Source) Collections Uses

func (s *Source) Collections() (cols []db.Collection, err error)

Collections returns a list of non-system tables from the database.

func (*Source) ConnectionURL Uses

func (s *Source) ConnectionURL() db.ConnectionURL

func (*Source) Context Uses

func (s *Source) Context() context.Context

func (*Source) Delete Uses

func (s *Source) Delete(db.Record) error

func (*Source) Driver Uses

func (s *Source) Driver() interface{}

Driver returns the underlying *mgo.Session instance.

func (*Source) Get Uses

func (s *Source) Get(db.Record, interface{}) error

func (*Source) Name Uses

func (s *Source) Name() string

Name returns the name of the database.

func (*Source) Open Uses

func (s *Source) Open(connURL db.ConnectionURL) error

Open attempts to connect to the database.

func (*Source) Ping Uses

func (s *Source) Ping() error

Ping checks whether a connection to the database is still alive by pinging it, establishing a connection if necessary.

func (*Source) Reset Uses

func (s *Source) Reset()

func (*Source) SQL Uses

func (s *Source) SQL() db.SQL

func (*Source) Save Uses

func (s *Source) Save(db.Record) error

func (*Source) SetConnMaxLifetime Uses

func (s *Source) SetConnMaxLifetime(time.Duration)

SetConnMaxLifetime is not supported.

func (*Source) SetMaxIdleConns Uses

func (s *Source) SetMaxIdleConns(int)

SetMaxIdleConns is not supported.

func (*Source) SetMaxOpenConns Uses

func (s *Source) SetMaxOpenConns(int)

SetMaxOpenConns is not supported.

func (*Source) Tx Uses

func (s *Source) Tx(func(db.Session) error) error

func (*Source) TxContext Uses

func (s *Source) TxContext(context.Context, func(tx db.Session) error, *sql.TxOptions) error

func (*Source) WithContext Uses

func (s *Source) WithContext(ctx context.Context) db.Session

Package mongo imports 17 packages (graph). Updated 2021-01-13. Refresh now. Tools for package owners.