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 ¶
- func Count(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document, ...) (int64, error)
- func Delete(ctx context.Context, s *SelectedServer, ns Namespace, ...) (bson.Reader, error)
- func Distinct(ctx context.Context, s *SelectedServer, ns Namespace, field string, ...) ([]interface{}, error)
- func Insert(ctx context.Context, s *SelectedServer, ns Namespace, docs []*bson.Document, ...) (rdr bson.Reader, err error)
- func KillCursors(ctx context.Context, s *SelectedServer, ns Namespace, cursors []int64) (bson.Reader, error)
- func Run(ctx context.Context, s *SelectedServer, db string, command interface{}) (bson.Reader, error)
- func RunCommand(ctx context.Context, s *SelectedServer, db string, command interface{}) (bson.Reader, error)
- func Update(ctx context.Context, s *SelectedServer, ns Namespace, ...) (bson.Reader, error)
- type AggregationOptions
- type Cursor
- func Aggregate(ctx context.Context, s *SelectedServer, ns Namespace, pipeline *bson.Array, ...) (Cursor, error)
- func Find(ctx context.Context, s *SelectedServer, ns Namespace, filter *bson.Document, ...) (Cursor, error)
- func FindOneAndDelete(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document, ...) (Cursor, error)
- func FindOneAndReplace(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document, ...) (Cursor, error)
- func FindOneAndUpdate(ctx context.Context, s *SelectedServer, ns Namespace, query *bson.Document, ...) (Cursor, error)
- func LegacyAggregate(ctx context.Context, s *SelectedServer, ns Namespace, pipeline *bson.Array, ...) (Cursor, error)
- func ListCollections(ctx context.Context, s *SelectedServer, db string, ...) (Cursor, error)
- func ListDatabases(ctx context.Context, s *SelectedServer, options ListDatabasesOptions) (Cursor, error)
- func ListIndexes(ctx context.Context, s *SelectedServer, ns Namespace, ...) (Cursor, error)
- func NewCursor(cursorResult bson.Reader, batchSize int32, server Server) (Cursor, error)
- func NewExhaustedCursor() (Cursor, error)
- type ListCollectionsOptions
- type ListDatabasesOptions
- type ListIndexesOptions
- type Namespace
- type SelectedServer
- type Server
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.
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 NewExhaustedCursor ¶
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 ¶
Namespace encapsulates a database and collection name, which together uniquely identifies a collection within a MongoDB cluster.
func NewNamespace ¶
NewNamespace returns a new Namespace for the given database and collection.
func ParseNamespace ¶
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.
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.
Source Files ¶
- aggregate.go
- count.go
- cursor.go
- delete.go
- distinct.go
- doc.go
- find.go
- find_one_and_delete.go
- find_one_and_replace.go
- find_one_and_update.go
- insert.go
- kill_cursors.go
- list_collections.go
- list_databases.go
- list_indexes.go
- namespace.go
- run.go
- run_command.go
- server.go
- single_result_cursor.go
- update.go
- util.go