ops

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package ops is not for public use.

The API for packages in the 'private' directory have no stability guarantee.

The packages within the 'private' directory would normally be put into an 'internal' directory to prohibit their use outside the 'mongo' directory. However, some MongoDB tools require very low-level access to the building blocks of a driver, so we have placed them under 'private' to allow these packages to be imported by projects that need them.

These package APIs may be modified in backwards-incompatible ways at any time.

You are strongly discouraged from directly using any packages under 'private'.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document,
	opts ...options.CountOptioner) (int64, error)

Count counts how many documents in a collection match a given query.

func Delete

func Delete(ctx context.Context, s *SelectedServer, ns Namespace, deleteDocs []*bson.Document,
	opts ...options.DeleteOptioner) (bson.Reader, error)

Delete executes an delete command with a given set of delete documents and options.

func Distinct

func Distinct(ctx context.Context, s *SelectedServer, ns Namespace, field string,
	query *bson.Document, opts ...options.DistinctOptioner) ([]interface{}, error)

Distinct returns the distinct values for a specified field across a single collection.

func Insert

func Insert(ctx context.Context, s *SelectedServer, ns Namespace, docs []*bson.Document,
	options ...options.InsertOptioner) (rdr bson.Reader, err error)

Insert executes an insert command for the given set of documents.

func KillCursors added in v0.0.2

func KillCursors(ctx context.Context, s *SelectedServer, ns Namespace,
	cursors []int64) (bson.Reader, error)

KillCursors kills one or more cursors.

func Run

func Run(ctx context.Context, s *SelectedServer, db string, command interface{}) (bson.Reader, error)

Run executes an arbitrary command against the given database.

func RunCommand

func RunCommand(ctx context.Context, s *SelectedServer, db string, command interface{},
) (bson.Reader, error)

RunCommand runs a command on the database.

func Update

func Update(ctx context.Context, s *SelectedServer, ns Namespace, updateDocs []*bson.Document,
	opt ...options.UpdateOptioner) (bson.Reader, error)

Update executes an update command with a given set of update documents and options.

Types

type AggregationOptions

type AggregationOptions struct {
	// Whether the server can use stable storage for sorting results.
	AllowDiskUse bool
	// The batch size for fetching results. A zero value indicates the server's default batch size.
	BatchSize int32
	// The maximum execution time.  A zero value indicates no maximum.
	MaxTime time.Duration
}

AggregationOptions are the options for the aggregate command.

type Cursor

type Cursor interface {

	// Get the ID of the cursor.
	ID() int64

	// Get the next result from the cursor.
	// Returns true if there were no errors and there is a next result.
	Next(context.Context) bool

	Decode(interface{}) error

	DecodeBytes() (bson.Reader, error)

	// Returns the error status of the cursor
	Err() error

	// Close the cursor.  Ordinarily this is a no-op as the server closes the cursor when it is exhausted.
	// Returns the error status of this cursor so that clients do not have to call Err() separately
	Close(context.Context) error
}

Cursor instances iterate a stream of documents. Each document is decoded into the result according to the rules of the bson package.

A typical usage of the Cursor interface would be:

cursor := ...    // get a cursor from some operation
ctx := ...       // create a context for the operation
var doc bson.D
for cursor.Next(ctx, &doc) {
	...
}
err := cursor.Close(ctx)

func Aggregate

func Aggregate(ctx context.Context, s *SelectedServer, ns Namespace, pipeline *bson.Array,
	hasDollarOut bool, opts ...options.AggregateOptioner) (Cursor, error)

Aggregate performs an aggregation.

This method takes both a read and a write concern. The caller should set the appropriate parameter based on whether there is a $out in the pipeline.

func Find

func Find(ctx context.Context, s *SelectedServer, ns Namespace, filter *bson.Document,
	findOptions ...options.FindOptioner) (Cursor, error)

Find executes a query.

func FindOneAndDelete

func FindOneAndDelete(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document,
	opts ...options.FindOneAndDeleteOptioner) (Cursor, error)

FindOneAndDelete modifies and returns a single document.

func FindOneAndReplace

func FindOneAndReplace(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document,
	replacement *bson.Document, opts ...options.FindOneAndReplaceOptioner) (Cursor, error)

FindOneAndReplace modifies and returns a single document.

func FindOneAndUpdate

func FindOneAndUpdate(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document,
	update *bson.Document, opts ...options.FindOneAndUpdateOptioner) (Cursor, error)

FindOneAndUpdate modifies and returns a single document.

func LegacyAggregate

func LegacyAggregate(ctx context.Context, s *SelectedServer, ns Namespace, pipeline *bson.Array, options AggregationOptions) (Cursor, error)

LegacyAggregate executes the aggregate command with the given pipeline and options.

The pipeline must encode as a BSON array of pipeline stages.

func ListCollections

func ListCollections(ctx context.Context, s *SelectedServer, db string, options ListCollectionsOptions) (Cursor, error)

ListCollections lists the collections in the given database with the given options.

func ListDatabases

func ListDatabases(ctx context.Context, s *SelectedServer, options ListDatabasesOptions) (Cursor, error)

ListDatabases lists the databases with the given options

func ListIndexes

func ListIndexes(ctx context.Context, s *SelectedServer, ns Namespace, options ListIndexesOptions) (Cursor, error)

ListIndexes lists the indexes on the given namespace.

func NewCursor

func NewCursor(cursorResult bson.Reader, batchSize int32, server Server) (Cursor, error)

NewCursor creates a new cursor from the given cursor result.

func NewExhaustedCursor

func NewExhaustedCursor() (Cursor, error)

NewExhaustedCursor creates a new exhausted cursor.

type ListCollectionsOptions

type ListCollectionsOptions struct {
	// A query filter for the collections
	Filter interface{}
	// The batch size for fetching results. A zero value indicates the server's default batch size.
	BatchSize int32
	// The maximum execution time in milliseconds. A zero value indicates no maximum.
	MaxTime time.Duration
}

ListCollectionsOptions are the options for listing collections.

type ListDatabasesOptions

type ListDatabasesOptions struct {
	// The maximum execution time in milliseconds.  A zero value indicates no maximum.
	MaxTime time.Duration
}

ListDatabasesOptions are the options for listing databases.

type ListIndexesOptions

type ListIndexesOptions struct {
	// The batch size for fetching results. A zero value indicates the server's default batch size.
	BatchSize int32
}

ListIndexesOptions are the options for listing indexes.

type Namespace

type Namespace struct {
	DB         string
	Collection string
}

Namespace encapsulates a database and collection name, which together uniquely identifies a collection within a MongoDB cluster.

func NewNamespace

func NewNamespace(db, collection string) Namespace

NewNamespace returns a new Namespace for the given database and collection.

func ParseNamespace

func ParseNamespace(fullName string) Namespace

ParseNamespace parses a namespace string into a Namespace.

The namespace string must contain at least one ".", the first of which is the separator between the database and collection names. If not, the default (invalid) Namespace is returned.

func (*Namespace) FullName

func (ns *Namespace) FullName() string

FullName returns the full namespace string, which is the result of joining the database name and the collection name with a "." character.

type SelectedServer

type SelectedServer struct {
	Server
	// ClusterKind indicates the kind of the cluster the
	// server was selected from.
	ClusterKind model.ClusterKind
	// ReadPref indicates the read preference that should
	// be passed to MongoS. This can be nil.
	ReadPref *readpref.ReadPref
}

SelectedServer represents a binding to a server. It contains a read preference in the case that needs to be passed on to the server during communication.

type Server

type Server interface {
	// Connection gets a connection to use.
	Connection(context.Context) (conn.Connection, error)
	// Model gets the description of the server.
	Model() *model.Server
}

Server represents a server.

Jump to

Keyboard shortcuts

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