Documentation ¶
Overview ¶
Package mongo provides a MongoDB Driver API for Go.
Basic usage of the driver starts with creating a Client from a connection string. To do so, call the NewClient and Connect functions:
client, err := mongo.NewClient("mongodb://foo:bar@localhost:27017") if err != nil { log.Fatal(err) } err = client.Connect(context.TODO()) if err != nil { log.Fatal(err) }
This will create a new client and start monitoring the MongoDB server on localhost. The Database and Collection types can be used to access the database:
collection := client.Database("baz").Collection("qux")
A Collection can be used to query the database or insert documents:
res, err := collection.InsertOne(context.Background(), map[string]string{"hello": "world"}) if err != nil { log.Fatal(err) } id := res.InsertedID
Several methods return a cursor, which can be used like this:
cur, err := collection.Find(context.Background(), nil) if err != nil { log.Fatal(err) } defer cur.Close(context.Background()) for cur.Next(context.Background()) { elem := bson.NewDocument() err := cur.Decode(elem) if err != nil { log.Fatal(err) } // do something with elem.... } if err := cur.Err(); err != nil { log.Fatal(err) }
Methods that only return a single document will return a *DocumentResult, which works like a *sql.Row:
result := bson.NewDocument() filter := bson.NewDocument(bson.EC.String("hello", "world")) err := collection.FindOne(context.Background(), filter).Decode(result) if err != nil { log.Fatal(err) } // do something with result...
Additional examples can be found under the examples directory in the driver's repository and on the MongoDB website.
Index ¶
- Variables
- func TransformDocument(document interface{}) (*bson.Document, error)
- type BulkWriteError
- type Client
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) ConnectionString() string
- func (c *Client) Database(name string, opts ...dbopt.Option) *Database
- func (c *Client) Disconnect(ctx context.Context) error
- func (c *Client) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) ([]string, error)
- func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) (ListDatabasesResult, error)
- func (c *Client) StartSession(opts ...sessionopt.Session) (*Session, error)
- func (c *Client) ValidSession(sess *session.Client) error
- type Collection
- func (coll *Collection) Aggregate(ctx context.Context, pipeline interface{}, opts ...aggregateopt.Aggregate) (Cursor, error)
- func (coll *Collection) Clone(opts ...collectionopt.Option) (*Collection, error)
- func (coll *Collection) Count(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error)
- func (coll *Collection) CountDocuments(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error)
- func (coll *Collection) DeleteMany(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*DeleteResult, error)
- func (coll *Collection) DeleteOne(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*DeleteResult, error)
- func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter interface{}, ...) ([]interface{}, error)
- func (coll *Collection) Drop(ctx context.Context, opts ...dropcollopt.DropColl) error
- func (coll *Collection) EstimatedDocumentCount(ctx context.Context, opts ...countopt.EstimatedDocumentCount) (int64, error)
- func (coll *Collection) Find(ctx context.Context, filter interface{}, opts ...findopt.Find) (Cursor, error)
- func (coll *Collection) FindOne(ctx context.Context, filter interface{}, opts ...findopt.One) *DocumentResult
- func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...findopt.DeleteOne) *DocumentResult
- func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{}, ...) *DocumentResult
- func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, ...) *DocumentResult
- func (coll *Collection) Indexes() IndexView
- func (coll *Collection) InsertMany(ctx context.Context, documents []interface{}, opts ...insertopt.Many) (*InsertManyResult, error)
- func (coll *Collection) InsertOne(ctx context.Context, document interface{}, opts ...insertopt.One) (*InsertOneResult, error)
- func (coll *Collection) Name() string
- func (coll *Collection) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, ...) (*UpdateResult, error)
- func (coll *Collection) UpdateMany(ctx context.Context, filter interface{}, update interface{}, ...) (*UpdateResult, error)
- func (coll *Collection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, ...) (*UpdateResult, error)
- func (coll *Collection) Watch(ctx context.Context, pipeline interface{}, ...) (Cursor, error)
- type Cursor
- type Database
- func (db *Database) Client() *Client
- func (db *Database) Collection(name string, opts ...collectionopt.Option) *Collection
- func (db *Database) Drop(ctx context.Context, opts ...dbopt.DropDB) error
- func (db *Database) ListCollections(ctx context.Context, filter *bson.Document, ...) (command.Cursor, error)
- func (db *Database) Name() string
- func (db *Database) ReadConcern() *readconcern.ReadConcern
- func (db *Database) ReadPreference() *readpref.ReadPref
- func (db *Database) RunCommand(ctx context.Context, runCommand interface{}, opts ...runcmdopt.Option) (bson.Reader, error)
- func (db *Database) WriteConcern() *writeconcern.WriteConcern
- type DatabaseSpecification
- type DeleteResult
- type Dialer
- type DocumentResult
- type IndexModel
- type IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Background(background bool) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Bits(bits int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) BucketSize(bucketSize int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Build() *bson.Document
- func (iob *IndexOptionsBuilder) Collation(collation *bson.Document) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) DefaultLanguage(defaultLanguage string) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) ExpireAfterSeconds(expireAfterSeconds int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) LanguageOverride(languageOverride string) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Max(max float64) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Min(min float64) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Name(name string) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) PartialFilterExpression(partialFilterExpression *bson.Document) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Sparse(sparse bool) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) SphereVersion(sphereVersion int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) StorageEngine(storageEngine *bson.Document) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) TextVersion(textVersion int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Unique(unique bool) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Version(version int32) *IndexOptionsBuilder
- func (iob *IndexOptionsBuilder) Weights(weights *bson.Document) *IndexOptionsBuilder
- type IndexView
- func (iv IndexView) CreateMany(ctx context.Context, models []IndexModel, opts ...indexopt.Create) ([]string, error)
- func (iv IndexView) CreateOne(ctx context.Context, model IndexModel, opts ...indexopt.Create) (string, error)
- func (iv IndexView) DropAll(ctx context.Context, opts ...indexopt.Drop) (bson.Reader, error)
- func (iv IndexView) DropOne(ctx context.Context, name string, opts ...indexopt.Drop) (bson.Reader, error)
- func (iv IndexView) List(ctx context.Context, opts ...indexopt.List) (Cursor, error)
- type InsertManyResult
- type InsertOneResult
- type ListDatabasesResult
- type Session
- func (s *Session) AbortTransaction(ctx context.Context) error
- func (s *Session) CommitTransaction(ctx context.Context) error
- func (s *Session) ConvertAggregateSession() *session.Client
- func (s *Session) ConvertChangeStreamSession() *session.Client
- func (s *Session) ConvertCountSession() *session.Client
- func (s *Session) ConvertDeleteOneSession() *session.Client
- func (s *Session) ConvertDeleteSession() *session.Client
- func (s *Session) ConvertDistinctSession() *session.Client
- func (s *Session) ConvertDropCollSession() *session.Client
- func (s *Session) ConvertDropDBSession() *session.Client
- func (s *Session) ConvertFindOneSession() *session.Client
- func (s *Session) ConvertFindSession() *session.Client
- func (s *Session) ConvertIndexSession() *session.Client
- func (s *Session) ConvertInsertSession() *session.Client
- func (s *Session) ConvertListCollectionsSession() *session.Client
- func (s *Session) ConvertListDatabasesSession() *session.Client
- func (s *Session) ConvertReplaceOneSession() *session.Client
- func (s *Session) ConvertReplaceSession() *session.Client
- func (s *Session) ConvertRunCmdSession() *session.Client
- func (s *Session) ConvertUpdateOneSession() *session.Client
- func (s *Session) ConvertUpdateSession() *session.Client
- func (s *Session) EndSession(ctx context.Context)
- func (s *Session) StartTransaction(opts ...transactionopt.Transaction) error
- type UpdateResult
- type WriteConcernError
- type WriteError
- type WriteErrors
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidIndexValue = errors.New("invalid index value")
ErrInvalidIndexValue indicates that the index Keys document has a value that isn't either a number or a string.
var ErrMissingResumeToken = errors.New("cannot provide resume functionality when the resume token is missing")
ErrMissingResumeToken indicates that a change stream notification from the server did not contain a resume token.
var ErrMultipleIndexDrop = errors.New("multiple indexes would be dropped")
ErrMultipleIndexDrop indicates that multiple indexes would be dropped from a call to IndexView.DropOne.
var ErrNoDocuments = errors.New("mongo: no documents in result")
ErrNoDocuments is returned by Decode when an operation that returns a DocumentResult doesn't return any documents.
var ErrNonStringIndexName = errors.New("index name must be a string")
ErrNonStringIndexName indicates that the index name specified in the options is not a string.
var ErrUnacknowledgedWrite = errors.New("unacknowledged write")
ErrUnacknowledgedWrite is returned from functions that have an unacknowledged write concern.
var ErrWrongClient = errors.New("session was not created by this client")
ErrWrongClient is returned when a user attempts to pass in a session created by a different client than the method call is using.
Functions ¶
func TransformDocument ¶
TransformDocument handles transforming a document of an allowable type into a *bson.Document. This method is called directly after most methods that have one or more parameters that are documents.
The supported types for document are:
bson.Marshaler bson.DocumentMarshaler bson.Reader []byte (must be a valid BSON document) io.Reader (only 1 BSON document will be read) A custom struct type
Types ¶
type BulkWriteError ¶ added in v0.0.4
type BulkWriteError struct { WriteErrors WriteErrors WriteConcernError *WriteConcernError }
BulkWriteError is an error returned from a bulk write operation.
func (BulkWriteError) Error ¶ added in v0.0.4
func (bwe BulkWriteError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs operations on a given topology.
func Connect ¶ added in v0.0.3
Connect creates a new Client and then initializes it using the Connect method.
func NewClientFromConnString ¶
func NewClientFromConnString(cs connstring.ConnString) (*Client, error)
NewClientFromConnString creates a new client to connect to a cluster, with configuration specified by the connection string.
func NewClientWithOptions ¶ added in v0.0.3
NewClientWithOptions creates a new client to connect to to a cluster specified by the connection string and the options manually passed in. If the same option is configured in both the connection string and the manual options, the manual option will be ignored.
func (*Client) Connect ¶ added in v0.0.3
Connect initializes the Client by starting background monitoring goroutines. This method must be called before a Client can be used.
func (*Client) ConnectionString ¶
ConnectionString returns the connection string of the cluster the client is connected to.
func (*Client) Disconnect ¶ added in v0.0.3
Disconnect closes sockets to the topology referenced by this Client. It will shut down any monitoring goroutines, close the idle connection pool, and will wait until all the in use connections have been returned to the connection pool and closed before returning. If the context expires via cancellation, deadline, or timeout before the in use connections have returned, the in use connections will be closed, resulting in the failure of any in flight read or write operations. If this method returns with no errors, all connections associated with this Client have been closed.
func (*Client) ListDatabaseNames ¶ added in v0.0.3
func (c *Client) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) ([]string, error)
ListDatabaseNames returns a slice containing the names of all of the databases on the server.
func (*Client) ListDatabases ¶ added in v0.0.3
func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) (ListDatabasesResult, error)
ListDatabases returns a ListDatabasesResult.
func (*Client) StartSession ¶ added in v0.0.10
func (c *Client) StartSession(opts ...sessionopt.Session) (*Session, error)
StartSession starts a new session.
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection performs operations on a given collection.
func (*Collection) Aggregate ¶
func (coll *Collection) Aggregate(ctx context.Context, pipeline interface{}, opts ...aggregateopt.Aggregate) (Cursor, error)
Aggregate runs an aggregation framework pipeline. A user can supply a custom context to this method.
See https://docs.mongodb.com/manual/aggregation/.
This method uses TransformDocument to turn the pipeline parameter into a *bson.Document. See TransformDocument for the list of valid types for pipeline.
func (*Collection) Clone ¶ added in v0.0.9
func (coll *Collection) Clone(opts ...collectionopt.Option) (*Collection, error)
Clone creates a copy of this collection with updated options, if any are given.
func (*Collection) Count ¶
func (coll *Collection) Count(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error)
Count gets the number of documents matching the filter. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) CountDocuments ¶ added in v0.0.11
func (coll *Collection) CountDocuments(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error)
CountDocuments gets the number of documents matching the filter. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses countDocumentsAggregatePipeline to turn the filter parameter and options into aggregate pipeline.
func (*Collection) DeleteMany ¶
func (coll *Collection) DeleteMany(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*DeleteResult, error)
DeleteMany deletes multiple documents from the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) DeleteOne ¶
func (coll *Collection) DeleteOne(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*DeleteResult, error)
DeleteOne deletes a single document from the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) Distinct ¶
func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...distinctopt.Distinct) ([]interface{}, error)
Distinct finds the distinct values for a specified field across a single collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) Drop ¶ added in v0.0.4
func (coll *Collection) Drop(ctx context.Context, opts ...dropcollopt.DropColl) error
Drop drops this collection from database.
func (*Collection) EstimatedDocumentCount ¶ added in v0.0.11
func (coll *Collection) EstimatedDocumentCount(ctx context.Context, opts ...countopt.EstimatedDocumentCount) (int64, error)
EstimatedDocumentCount gets an estimate of the count of documents in a collection using collection metadata.
func (*Collection) Find ¶
func (coll *Collection) Find(ctx context.Context, filter interface{}, opts ...findopt.Find) (Cursor, error)
Find finds the documents matching a model. A user can supply a custom context to this method.
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) FindOne ¶
func (coll *Collection) FindOne(ctx context.Context, filter interface{}, opts ...findopt.One) *DocumentResult
FindOne returns up to one document that matches the model. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) FindOneAndDelete ¶
func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...findopt.DeleteOne) *DocumentResult
FindOneAndDelete find a single document and deletes it, returning the original in result. The document to return may be nil.
A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter parameter into a *bson.Document. See TransformDocument for the list of valid types for filter.
func (*Collection) FindOneAndReplace ¶
func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{}, opts ...findopt.ReplaceOne) *DocumentResult
FindOneAndReplace finds a single document and replaces it, returning either the original or the replaced document. The document to return may be nil.
A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter and replacement parameter into a *bson.Document. See TransformDocument for the list of valid types for filter and replacement.
func (*Collection) FindOneAndUpdate ¶
func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...findopt.UpdateOne) *DocumentResult
FindOneAndUpdate finds a single document and updates it, returning either the original or the updated. The document to return may be nil.
A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter and update parameter into a *bson.Document. See TransformDocument for the list of valid types for filter and update.
func (*Collection) Indexes ¶ added in v0.0.3
func (coll *Collection) Indexes() IndexView
Indexes returns the index view for this collection.
func (*Collection) InsertMany ¶
func (coll *Collection) InsertMany(ctx context.Context, documents []interface{}, opts ...insertopt.Many) (*InsertManyResult, error)
InsertMany inserts the provided documents. A user can supply a custom context to this method.
Currently, batching is not implemented for this operation. Because of this, extremely large sets of documents will not fit into a single BSON document to be sent to the server, so the operation will fail.
This method uses TransformDocument to turn the documents parameter into a *bson.Document. See TransformDocument for the list of valid types for documents.
func (*Collection) InsertOne ¶
func (coll *Collection) InsertOne(ctx context.Context, document interface{}, opts ...insertopt.One) (*InsertOneResult, error)
InsertOne inserts a single document into the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the document parameter into a *bson.Document. See TransformDocument for the list of valid types for document.
TODO(skriptble): Determine if we should unwrap the value for the InsertOneResult or just return the bson.Element or a bson.Value.
func (*Collection) Name ¶ added in v0.0.4
func (coll *Collection) Name() string
Name provides access to the name of the collection.
func (*Collection) ReplaceOne ¶
func (coll *Collection) ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, opts ...replaceopt.Replace) (*UpdateResult, error)
ReplaceOne replaces a single document in the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter and replacement parameter into a *bson.Document. See TransformDocument for the list of valid types for filter and replacement.
func (*Collection) UpdateMany ¶
func (coll *Collection) UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...updateopt.Update) (*UpdateResult, error)
UpdateMany updates multiple documents in the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter and update parameter into a *bson.Document. See TransformDocument for the list of valid types for filter and update.
func (*Collection) UpdateOne ¶
func (coll *Collection) UpdateOne(ctx context.Context, filter interface{}, update interface{}, options ...updateopt.Update) (*UpdateResult, error)
UpdateOne updates a single document in the collection. A user can supply a custom context to this method, or nil to default to context.Background().
This method uses TransformDocument to turn the filter and update parameter into a *bson.Document. See TransformDocument for the list of valid types for filter and update.
func (*Collection) Watch ¶ added in v0.0.2
func (coll *Collection) Watch(ctx context.Context, pipeline interface{}, opts ...changestreamopt.ChangeStream) (Cursor, error)
Watch returns a change stream cursor used to receive notifications of changes to the collection. This method is preferred to running a raw aggregation with a $changeStream stage because it supports resumability in the case of some errors.
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. 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:
var cur Cursor ctx := context.Background() defer cur.Close(ctx) for cur.Next(ctx) { elem := bson.NewDocument() if err := cur.Decode(elem); err != nil { log.Fatal(err) } // do something with elem.... } if err := cur.Err(); err != nil { log.Fatal(err) }
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database performs operations on a given database.
func (*Database) Collection ¶
func (db *Database) Collection(name string, opts ...collectionopt.Option) *Collection
Collection gets a handle for a given collection in the database.
func (*Database) ListCollections ¶ added in v0.0.6
func (db *Database) ListCollections(ctx context.Context, filter *bson.Document, opts ...listcollectionopt.ListCollections) (command.Cursor, error)
ListCollections list collections from mongodb database.
func (*Database) ReadConcern ¶ added in v0.0.13
func (db *Database) ReadConcern() *readconcern.ReadConcern
ReadConcern returns the read concern of this database.
func (*Database) ReadPreference ¶ added in v0.0.13
ReadPreference returns the read preference of this database.
func (*Database) RunCommand ¶
func (db *Database) RunCommand(ctx context.Context, runCommand interface{}, opts ...runcmdopt.Option) (bson.Reader, error)
RunCommand runs a command on the database. A user can supply a custom context to this method, or nil to default to context.Background().
func (*Database) WriteConcern ¶ added in v0.0.13
func (db *Database) WriteConcern() *writeconcern.WriteConcern
WriteConcern returns the write concern of this database.
type DatabaseSpecification ¶ added in v0.0.3
DatabaseSpecification is the information for a single database returned from a ListDatabases operation.
type DeleteResult ¶
type DeleteResult struct { // The number of documents that were deleted. DeletedCount int64 `bson:"n"` }
DeleteResult is a result of an DeleteOne operation.
type Dialer ¶ added in v0.0.3
type Dialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
Dialer is used to make network connections.
type DocumentResult ¶
type DocumentResult struct {
// contains filtered or unexported fields
}
DocumentResult represents a single document returned from an operation. If the operation returned an error, the Err method of DocumentResult will return that error.
func (*DocumentResult) Decode ¶
func (dr *DocumentResult) Decode(v interface{}) error
Decode will attempt to decode the first document into v. If there was an error from the operation that created this DocumentResult then the error will be returned. If there were no returned documents, ErrNoDocuments is returned.
type IndexModel ¶ added in v0.0.3
IndexModel contains information about an index.
type IndexOptionsBuilder ¶ added in v0.0.7
type IndexOptionsBuilder struct {
// contains filtered or unexported fields
}
IndexOptionsBuilder constructs a BSON document for index options
func NewIndexOptionsBuilder ¶ added in v0.0.7
func NewIndexOptionsBuilder() *IndexOptionsBuilder
NewIndexOptionsBuilder creates a new instance of IndexOptionsBuilder
func (*IndexOptionsBuilder) Background ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Background(background bool) *IndexOptionsBuilder
Background sets the background option
func (*IndexOptionsBuilder) Bits ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Bits(bits int32) *IndexOptionsBuilder
Bits sets the bits option
func (*IndexOptionsBuilder) BucketSize ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) BucketSize(bucketSize int32) *IndexOptionsBuilder
BucketSize sets the bucketSize option
func (*IndexOptionsBuilder) Build ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Build() *bson.Document
Build returns the BSON document from the builder
func (*IndexOptionsBuilder) Collation ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Collation(collation *bson.Document) *IndexOptionsBuilder
Collation sets the collation option
func (*IndexOptionsBuilder) DefaultLanguage ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) DefaultLanguage(defaultLanguage string) *IndexOptionsBuilder
DefaultLanguage sets the defaultLanguage option
func (*IndexOptionsBuilder) ExpireAfterSeconds ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) ExpireAfterSeconds(expireAfterSeconds int32) *IndexOptionsBuilder
ExpireAfterSeconds sets the expireAfterSeconds option
func (*IndexOptionsBuilder) LanguageOverride ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) LanguageOverride(languageOverride string) *IndexOptionsBuilder
LanguageOverride sets the languageOverride option
func (*IndexOptionsBuilder) Max ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Max(max float64) *IndexOptionsBuilder
Max sets the max option
func (*IndexOptionsBuilder) Min ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Min(min float64) *IndexOptionsBuilder
Min sets the min option
func (*IndexOptionsBuilder) Name ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Name(name string) *IndexOptionsBuilder
Name sets the name option
func (*IndexOptionsBuilder) PartialFilterExpression ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) PartialFilterExpression(partialFilterExpression *bson.Document) *IndexOptionsBuilder
PartialFilterExpression sets the partialFilterExpression option
func (*IndexOptionsBuilder) Sparse ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Sparse(sparse bool) *IndexOptionsBuilder
Sparse sets the sparse option
func (*IndexOptionsBuilder) SphereVersion ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) SphereVersion(sphereVersion int32) *IndexOptionsBuilder
SphereVersion sets the sphereVersion option
func (*IndexOptionsBuilder) StorageEngine ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) StorageEngine(storageEngine *bson.Document) *IndexOptionsBuilder
StorageEngine sets the storageEngine option
func (*IndexOptionsBuilder) TextVersion ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) TextVersion(textVersion int32) *IndexOptionsBuilder
TextVersion sets the textVersion option
func (*IndexOptionsBuilder) Unique ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Unique(unique bool) *IndexOptionsBuilder
Unique sets the unique option
func (*IndexOptionsBuilder) Version ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Version(version int32) *IndexOptionsBuilder
Version sets the version option
func (*IndexOptionsBuilder) Weights ¶ added in v0.0.7
func (iob *IndexOptionsBuilder) Weights(weights *bson.Document) *IndexOptionsBuilder
Weights sets the weights option
type IndexView ¶ added in v0.0.3
type IndexView struct {
// contains filtered or unexported fields
}
IndexView is used to create, drop, and list indexes on a given collection.
func (IndexView) CreateMany ¶ added in v0.0.3
func (iv IndexView) CreateMany(ctx context.Context, models []IndexModel, opts ...indexopt.Create) ([]string, error)
CreateMany creates multiple indexes in the collection specified by the models. The names of the creates indexes are returned.
func (IndexView) CreateOne ¶ added in v0.0.3
func (iv IndexView) CreateOne(ctx context.Context, model IndexModel, opts ...indexopt.Create) (string, error)
CreateOne creates a single index in the collection specified by the model.
type InsertManyResult ¶
type InsertManyResult struct {
// Maps the indexes of inserted documents to their _id fields.
InsertedIDs []interface{}
}
InsertManyResult is a result of an InsertMany operation.
type InsertOneResult ¶
type InsertOneResult struct {
// The identifier that was inserted.
InsertedID interface{}
}
InsertOneResult is a result of an InsertOne operation.
InsertedID will be a Go type that corresponds to a BSON type.
type ListDatabasesResult ¶ added in v0.0.3
type ListDatabasesResult struct { Databases []DatabaseSpecification TotalSize int64 }
ListDatabasesResult is a result of a ListDatabases operation. Each specification is a description of the datbases on the server.
type Session ¶ added in v0.0.10
type Session struct { aggregateopt.AggregateSessionOpt changestreamopt.ChangeStreamSessionOpt countopt.CountSessionOpt deleteopt.DeleteSessionOpt distinctopt.DistinctSessionOpt dbopt.DropDBSessionOpt findopt.FindSessionOpt dropcollopt.DropCollSessionOpt listcollectionopt.ListCollectionsSessionOpt updateopt.UpdateSessionOpt replaceopt.ReplaceSessionOpt indexopt.IndexSessionOpt insertopt.InsertSessionOpt runcmdopt.RunCmdSessionOpt listdbopt.ListDatabasesSessionOpt *session.Client // contains filtered or unexported fields }
Session represents a set of sequential operations executed by an application that are related in some way.
func (*Session) AbortTransaction ¶ added in v0.0.12
AbortTransaction aborts the session's transaction, returning any errors and error codes
func (*Session) CommitTransaction ¶ added in v0.0.12
CommitTransaction commits the sesson's transaction.
func (*Session) ConvertAggregateSession ¶ added in v0.0.10
ConvertAggregateSession implements the AggregateSession interface.
func (*Session) ConvertChangeStreamSession ¶ added in v0.0.10
ConvertChangeStreamSession implements the ChangeStreamSession interface.
func (*Session) ConvertCountSession ¶ added in v0.0.10
ConvertCountSession implements the CountSession interface.
func (*Session) ConvertDeleteOneSession ¶ added in v0.0.10
ConvertDeleteOneSession implements the DeleteOneSession interface.
func (*Session) ConvertDeleteSession ¶ added in v0.0.10
ConvertDeleteSession implements the DeleteSession interface.
func (*Session) ConvertDistinctSession ¶ added in v0.0.10
ConvertDistinctSession implements the DistinctSession interface.
func (*Session) ConvertDropCollSession ¶ added in v0.0.10
ConvertDropCollSession implements the DropCollSession interface
func (*Session) ConvertDropDBSession ¶ added in v0.0.10
ConvertDropDBSession implements the DropDBSession interface.
func (*Session) ConvertFindOneSession ¶ added in v0.0.10
ConvertFindOneSession implements the FindOneSession interface.
func (*Session) ConvertFindSession ¶ added in v0.0.10
ConvertFindSession implements the FindSession interface.
func (*Session) ConvertIndexSession ¶ added in v0.0.10
ConvertIndexSession implements the IndexSession interface.
func (*Session) ConvertInsertSession ¶ added in v0.0.10
ConvertInsertSession implements the InsertManySession and InsertOneSession interfaces.
func (*Session) ConvertListCollectionsSession ¶ added in v0.0.10
ConvertListCollectionsSession implements the ListCollectionsSession interface.
func (*Session) ConvertListDatabasesSession ¶ added in v0.0.10
ConvertListDatabasesSession implements the ListDatabasesSession interface
func (*Session) ConvertReplaceOneSession ¶ added in v0.0.10
ConvertReplaceOneSession implements the ReplaceOneSession interface.
func (*Session) ConvertReplaceSession ¶ added in v0.0.10
ConvertReplaceSession implements the ReplaceSession interface.
func (*Session) ConvertRunCmdSession ¶ added in v0.0.12
ConvertRunCmdSession implements the RunCmdSession interface.
func (*Session) ConvertUpdateOneSession ¶ added in v0.0.10
ConvertUpdateOneSession implements the UpdateOneSession interface.
func (*Session) ConvertUpdateSession ¶ added in v0.0.10
ConvertUpdateSession implements the UpdateSession interface.
func (*Session) EndSession ¶ added in v0.0.12
EndSession ends the session.
func (*Session) StartTransaction ¶ added in v0.0.12
func (s *Session) StartTransaction(opts ...transactionopt.Transaction) error
StartTransaction starts a transaction for this session.
type UpdateResult ¶
type UpdateResult struct { // The number of documents that matched the filter. MatchedCount int64 // The number of documents that were modified. ModifiedCount int64 // The identifier of the inserted document if an upsert took place. UpsertedID interface{} }
UpdateResult is a result of an update operation.
UpsertedID will be a Go type that corresponds to a BSON type.
func (*UpdateResult) UnmarshalBSON ¶
func (result *UpdateResult) UnmarshalBSON(b []byte) error
UnmarshalBSON implements the bson.Unmarshaler interface.
type WriteConcernError ¶ added in v0.0.4
WriteConcernError is a write concern failure that occurred as a result of a write operation.
func (WriteConcernError) Error ¶ added in v0.0.4
func (wce WriteConcernError) Error() string
type WriteError ¶ added in v0.0.4
WriteError is a non-write concern failure that occurred as a result of a write operation.
func (WriteError) Error ¶ added in v0.0.4
func (we WriteError) Error() string
type WriteErrors ¶ added in v0.0.4
type WriteErrors []WriteError
WriteErrors is a group of non-write concern failures that occurred as a result of a write operation.
func (WriteErrors) Error ¶ added in v0.0.4
func (we WriteErrors) Error() string