mgx

package module
v0.0.0-...-fc1657f Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 10 Imported by: 0

README

MongoX (mgx)

A Golang MongoDB API to simplify the use of MongoDB in your projects.

Installation

go get github.com/akmalfairuz/mgx
Example Usage
package main

import (
    "fmt"

    "github.com/akmalfairuz/mgx"
)

func main() {
    db, err := mgx.New("mongodb://localhost:27017", "test")
    if err != nil {
        panic(err)
    }
    r := db.Collection("users").Insert(mgx.M{
        "name": "John Doe",
        "age":  20,
    }, mgx.NewInsertOneOptions().BypassDocumentValidation().Comment("John Doe user"))
    if r.Err != nil {
        panic(r.Err)
    }
    fmt.Println(r.InsertedID)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrDuplicateKey

func IsErrDuplicateKey(err error) bool

IsErrDuplicateKey ...

func IsErrEmptySlice

func IsErrEmptySlice(err error) bool

IsErrEmptySlice ...

func IsErrNetwork

func IsErrNetwork(err error) bool

IsErrNetwork ...

func IsErrNilCursor

func IsErrNilCursor(err error) bool

IsErrNilCursor ...

func IsErrNilDocument

func IsErrNilDocument(err error) bool

IsErrNilDocument ...

func IsErrNoDocuments

func IsErrNoDocuments(err error) bool

IsErrNoDocuments returns true if the error is a mongo.ErrNoDocuments.

func IsErrTimeout

func IsErrTimeout(err error) bool

IsErrTimeout ...

Types

type AggregateOptions

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

AggregateOptions is a wrapper around mongo options.

func NewAggregateOptions

func NewAggregateOptions() *AggregateOptions

NewAggregateOptions creates a new AggregateOptions.

func (*AggregateOptions) AllowDiskUse

func (o *AggregateOptions) AllowDiskUse(v ...bool) *AggregateOptions

AllowDiskUse specifies whether to allow disk use.

func (*AggregateOptions) BatchSize

func (o *AggregateOptions) BatchSize(v int32) *AggregateOptions

BatchSize specifies the number of documents to return per batch.

func (*AggregateOptions) BypassDocumentValidation

func (o *AggregateOptions) BypassDocumentValidation(v ...bool) *AggregateOptions

BypassDocumentValidation specifies whether to bypass document validation during the aggregate operation.

func (*AggregateOptions) Collation

func (o *AggregateOptions) Collation(v *Collation) *AggregateOptions

Collation specifies a collation.

func (*AggregateOptions) Comment

func (o *AggregateOptions) Comment(v string) *AggregateOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*AggregateOptions) Custom

func (o *AggregateOptions) Custom(v bson.M) *AggregateOptions

Custom specifies options to be added to aggregate expression.

func (*AggregateOptions) Hint

Hint specifies the index to use.

func (*AggregateOptions) Let

Let specifies variables that can be accessed in the pipeline.

func (*AggregateOptions) MaxAwaitTime

func (o *AggregateOptions) MaxAwaitTime(v time.Duration) *AggregateOptions

MaxAwaitTime specifies the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. This only applies to tailable cursor queries issued against a replica set. The default value is nil, which means that there is no maximum await time.

func (*AggregateOptions) MaxTime

MaxTime specifies the maximum amount of time to allow the query to run.

type AggregateResult

type AggregateResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
}

type ArrayFilters

type ArrayFilters struct {
	options.ArrayFilters
}

type Collation

type Collation struct {
	*options.Collation
}

type Collection

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

Collection is a wrapper around mongo.Collection. It provides more simple methods for common operations.

func (*Collection) Aggregate

func (c *Collection) Aggregate(result, pipeline []any, opts ...*AggregateOptions) *AggregateResult

Aggregate performs an aggregation framework pipeline against the collection.

func (*Collection) Count

func (c *Collection) Count(filter any, opts ...*CountOptions) *CountResult

Count returns the number of documents in the collection.

func (*Collection) CreateIndex

func (c *Collection) CreateIndex(model IndexModel, opts ...*CreateIndexesOptions) *CreateIndexResult

CreateIndex creates a single index on the collection.

func (*Collection) CreateIndexes

func (c *Collection) CreateIndexes(models []IndexModel, opts ...*CreateIndexesOptions) *CreateIndexesResult

CreateIndexes creates multiple indexes on the collection.

func (*Collection) Delete

func (c *Collection) Delete(filter any, opts ...*DeleteOptions) *DeleteResult

Delete is an alias for DeleteOne.

func (*Collection) DeleteMany

func (c *Collection) DeleteMany(filter any, opts ...*options.DeleteOptions) *DeleteResult

DeleteMany deletes multiple documents from the collection.

func (*Collection) DeleteOne

func (c *Collection) DeleteOne(filter any, opts ...*DeleteOptions) *DeleteResult

DeleteOne deletes a single document from the collection.

func (*Collection) Distinct

func (c *Collection) Distinct(key string, filter any, opts ...*DistinctOptions) *DistinctResult

Distinct returns a list of distinct values for the given key across a single collection.

func (*Collection) DropIndex

func (c *Collection) DropIndex(name string, opts ...*DropIndexesOptions) *DropIndexResult

DropIndex drops a single index from the collection.

func (*Collection) DropIndexes

func (c *Collection) DropIndexes(opts ...*DropIndexesOptions) *DropIndexesResult

DropIndexes drops all indexes from the collection.

func (*Collection) Find

func (c *Collection) Find(filter, result any, opts ...*FindOptions) *FindResult

Find returns all documents that match the filter.

func (*Collection) FindOne

func (c *Collection) FindOne(filter, result any, opt ...*GetOptions) *SingleResult

FindOne returns the first document that matches the filter.

func (*Collection) FindOneAndDelete

func (c *Collection) FindOneAndDelete(filter, result any, opt ...*FindOneAndDeleteOptions) *SingleResult

FindOneAndDelete returns the first document that matches the filter.

func (*Collection) FindOneAndReplace

func (c *Collection) FindOneAndReplace(filter, replacement, result any, opt ...*FindOneAndReplaceOptions) *SingleResult

FindOneAndReplace returns the first document that matches the filter.

func (*Collection) FindOneAndUpdate

func (c *Collection) FindOneAndUpdate(filter, update, result any, opts ...*FindOneAndUpdateOptions) *SingleResult

FindOneAndUpdate returns the first document that matches the filter.

func (*Collection) Get

func (c *Collection) Get(filter, result any, opts ...*GetOptions) *SingleResult

Get returns the first document that matches the filter.

func (*Collection) Insert

func (c *Collection) Insert(doc any, opts ...*InsertOneOptions) *InsertResult

Insert is an alias for InsertOne.

func (*Collection) InsertMany

func (c *Collection) InsertMany(docs []any, opts ...*InsertManyOptions) *InsertManyResult

InsertMany inserts multiple documents into the collection.

func (*Collection) InsertOne

func (c *Collection) InsertOne(doc any, opts ...*InsertOneOptions) *InsertResult

InsertOne inserts a single document into the collection.

func (*Collection) ListIndexes

func (c *Collection) ListIndexes(result []IndexModel, opts ...*ListIndexesOptions) *ListIndexesResult

ListIndexes lists the indexes on the collection.

func (*Collection) ReplaceOne

func (c *Collection) ReplaceOne(filter, replacement any, opts ...*ReplaceOptions) *UpdateResult

ReplaceOne replaces a single document in the collection.

func (*Collection) Update

func (c *Collection) Update(filter, update any, opts ...*UpdateOptions) *UpdateResult

Update is an alias for UpdateOne.

func (*Collection) UpdateMany

func (c *Collection) UpdateMany(filter, update any, opts ...*options.UpdateOptions) *UpdateResult

UpdateMany updates multiple documents in the collection.

func (*Collection) UpdateOne

func (c *Collection) UpdateOne(filter, update any, opts ...*UpdateOptions) *UpdateResult

UpdateOne updates a single document in the collection.

func (*Collection) Watch

func (c *Collection) Watch(pipeline []any, opts ...*WatchOptions) *WatchResult

Watch creates a change stream cursor for a collection.

func (*Collection) WithContext

func (c *Collection) WithContext(ctx context.Context) *Collection

WithContext sets the context for the collection. This context will be used for all operations on the collection.

type CountOptions

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

CountOptions is a wrapper around mongo options.

func NewCountOptions

func NewCountOptions() *CountOptions

NewCountOptions creates a new CountOptions.

func (*CountOptions) Collation

func (o *CountOptions) Collation(v *options.Collation) *CountOptions

Collation specifies a collation.

func (*CountOptions) Comment

func (o *CountOptions) Comment(v string) *CountOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*CountOptions) Hint

func (o *CountOptions) Hint(v any) *CountOptions

Hint specifies the index to use.

func (*CountOptions) Limit

func (o *CountOptions) Limit(v int64) *CountOptions

Limit specifies the maximum number of documents to count.

func (*CountOptions) MaxTime

func (o *CountOptions) MaxTime(v time.Duration) *CountOptions

MaxTime specifies the maximum amount of time to allow the query to run.

func (*CountOptions) Skip

func (o *CountOptions) Skip(v int64) *CountOptions

Skip specifies the number of documents to skip before returning.

type CountResult

type CountResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Count is the number of documents returned by the operation.
	Count int64
}

type CreateCollectionResult

type CreateCollectionResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Name is the name of the created collection.
	Name string
	// Collection is the created collection.
	Collection *Collection
}

type CreateIndexResult

type CreateIndexResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Name is the name of the created index.
	Name string
}

type CreateIndexesOptions

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

CreateIndexesOptions is a wrapper around mongo options.

func NewCreateIndexesOptions

func NewCreateIndexesOptions() *CreateIndexesOptions

NewCreateIndexesOptions creates a new CreateIndexesOptions.

func (*CreateIndexesOptions) CommitQuorumInt

func (o *CreateIndexesOptions) CommitQuorumInt(v int32) *CreateIndexesOptions

CommitQuorumInt specifies the number of data-bearing members of a replica set, including the primary, that must complete the index builds successfully before the primary marks the indexes as ready.

func (*CreateIndexesOptions) CommitQuorumMajority

func (o *CreateIndexesOptions) CommitQuorumMajority() *CreateIndexesOptions

CommitQuorumMajority specifies the number of data-bearing members of a replica set, including the primary, that must complete the index builds successfully before the primary marks the indexes as ready.

func (*CreateIndexesOptions) CommitQuorumString

func (o *CreateIndexesOptions) CommitQuorumString(v string) *CreateIndexesOptions

CommitQuorumString specifies the number of data-bearing members of a replica set, including the primary, that must complete the index builds successfully before the primary marks the indexes as ready.

func (*CreateIndexesOptions) CommitQuorumVotingMembers

func (o *CreateIndexesOptions) CommitQuorumVotingMembers() *CreateIndexesOptions

CommitQuorumVotingMembers specifies the number of data-bearing members of a replica set, including the primary, that must complete the index builds successfully before the primary marks the indexes as ready.

func (*CreateIndexesOptions) MaxTime

MaxTime specifies the maximum amount of time to allow the query to run.

type CreateIndexesResult

type CreateIndexesResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Names is the names of the created indexes.
	Names []string
}

type CursorType

type CursorType int8
const (
	// CursorNonTailable specifies that a cursor should close after retrieving the last data.
	CursorNonTailable CursorType = iota
	// CursorTailable specifies that a cursor should not close when the last data is retrieved and can be resumed later.
	CursorTailable
	// CursorTailableAwait specifies that a cursor should not close when the last data is retrieved and
	// that it should block for a certain amount of time for new data before returning no data.
	CursorTailableAwait
)

type D

type D = bson.D

type Database

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

Database ...

func New

func New(uri, database string, ctx ...context.Context) (*Database, error)

New creates a new MongoX instance.

func (*Database) Close

func (db *Database) Close(ctx ...context.Context) error

Close closes the connection to the database.

func (*Database) Collection

func (db *Database) Collection(v string, ctx ...context.Context) *Collection

Collection returns a collection with the given name.

func (*Database) CreateCollection

func (db *Database) CreateCollection(v string, ctx ...context.Context) *CreateCollectionResult

CreateCollection creates a new collection with the given name.

func (*Database) DropCollection

func (db *Database) DropCollection(v string) *DropCollectionResult

DropCollection drops the collection with the given name.

func (*Database) IsCollectionExists

func (db *Database) IsCollectionExists(v string) bool

IsCollectionExists checks if a collection with the given name exists.

func (*Database) ListCollectionNames

func (db *Database) ListCollectionNames(filter any, opts ...*ListCollectionsOptions) *ListCollectionsResult

ListCollectionNames lists all collection names in the database.

func (*Database) ListCollections

func (db *Database) ListCollections(result, filter any, opts ...*ListCollectionsOptions) *ListCollectionsResult

ListCollections lists all collections in the database.

func (*Database) WithContext

func (db *Database) WithContext(ctx context.Context) *Database

func (*Database) WithTransaction

func (db *Database) WithTransaction(fn func(ctx mongo.SessionContext) (any, error), opt ...*TransactionOptions) (any, error)

type DeleteOptions

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

DeleteOptions is a wrapper around mongo options.

func NewDeleteOptions

func NewDeleteOptions() *DeleteOptions

NewDeleteOptions creates a new DeleteOptions.

func (*DeleteOptions) Collation

func (o *DeleteOptions) Collation(v *options.Collation) *DeleteOptions

Collation specifies a collation.

func (*DeleteOptions) Comment

func (o *DeleteOptions) Comment(v string) *DeleteOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*DeleteOptions) Hint

func (o *DeleteOptions) Hint(v any) *DeleteOptions

Hint specifies the index to use.

func (*DeleteOptions) Let

func (o *DeleteOptions) Let(v any) *DeleteOptions

Let specifies variables accessible from the delete expression.

type DeleteResult

type DeleteResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// DeletedCount is the number of documents deleted by the operation.
	DeletedCount int64
}

type DistinctOptions

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

DistinctOptions is a wrapper around mongo options.

func NewDistinctOptions

func NewDistinctOptions() *DistinctOptions

NewDistinctOptions creates a new DistinctOptions.

func (*DistinctOptions) Collation

func (o *DistinctOptions) Collation(v *Collation) *DistinctOptions

Collation specifies a collation.

func (*DistinctOptions) Comment

func (o *DistinctOptions) Comment(v string) *DistinctOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*DistinctOptions) MaxTime

MaxTime specifies the maximum amount of time to allow the query to run.

type DistinctResult

type DistinctResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Result is the list of distinct values returned by the operation.
	Result []any
}

type DropCollectionResult

type DropCollectionResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Name is the name of the dropped collection.
	Name string
}

type DropIndexResult

type DropIndexResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Name is the name of the dropped index.
	Name string
}

type DropIndexesOptions

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

DropIndexesOptions is a wrapper around mongo options.

func NewDropIndexesOptions

func NewDropIndexesOptions() *DropIndexesOptions

NewDropIndexesOptions creates a new DropIndexesOptions.

func (*DropIndexesOptions) MaxTime

MaxTime specifies the maximum amount of time to allow the query to run.

type DropIndexesResult

type DropIndexesResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// Names is the names of the dropped indexes.
	Names []string
}

type FindOneAndDeleteOptions

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

FindOneAndDeleteOptions is a wrapper around mongo options.

func NewFindOneAndDeleteOptions

func NewFindOneAndDeleteOptions() *FindOneAndDeleteOptions

NewFindOneAndDeleteOptions creates a new FindOneAndDeleteOptions.

func (*FindOneAndDeleteOptions) Collation

func (*FindOneAndDeleteOptions) Comment

func (*FindOneAndDeleteOptions) Hint

func (*FindOneAndDeleteOptions) Let

func (*FindOneAndDeleteOptions) MaxTime

func (*FindOneAndDeleteOptions) Projection

func (*FindOneAndDeleteOptions) Sort

type FindOneAndReplaceOptions

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

FindOneAndReplaceOptions is a wrapper around mongo options.

func NewFindOneAndReplaceOptions

func NewFindOneAndReplaceOptions() *FindOneAndReplaceOptions

NewFindOneAndReplaceOptions creates a new FindOneAndReplaceOptions.

func (*FindOneAndReplaceOptions) BypassDocumentValidation

func (o *FindOneAndReplaceOptions) BypassDocumentValidation(v ...bool) *FindOneAndReplaceOptions

func (*FindOneAndReplaceOptions) Collation

func (*FindOneAndReplaceOptions) Comment

func (*FindOneAndReplaceOptions) Hint

func (*FindOneAndReplaceOptions) Let

func (*FindOneAndReplaceOptions) MaxTime

func (*FindOneAndReplaceOptions) Projection

func (*FindOneAndReplaceOptions) ReturnDocument

func (*FindOneAndReplaceOptions) Sort

func (*FindOneAndReplaceOptions) Upsert

type FindOneAndUpdateOptions

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

FindOneAndUpdateOptions is a wrapper around mongo options.

func NewFindOneAndUpdateOptions

func NewFindOneAndUpdateOptions() *FindOneAndUpdateOptions

NewFindOneAndUpdateOptions creates a new FindOneAndUpdateOptions.

func (*FindOneAndUpdateOptions) ArrayFilters

func (*FindOneAndUpdateOptions) BypassDocumentValidation

func (o *FindOneAndUpdateOptions) BypassDocumentValidation(v ...bool) *FindOneAndUpdateOptions

func (*FindOneAndUpdateOptions) Collation

func (*FindOneAndUpdateOptions) Comment

func (*FindOneAndUpdateOptions) Hint

func (*FindOneAndUpdateOptions) Let

func (*FindOneAndUpdateOptions) MaxTime

func (*FindOneAndUpdateOptions) Projection

func (*FindOneAndUpdateOptions) ReturnDocument

func (*FindOneAndUpdateOptions) Sort

func (*FindOneAndUpdateOptions) Upsert

type FindOptions

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

FindOptions is a wrapper around mongo options.

func NewFindOptions

func NewFindOptions() *FindOptions

NewFindOptions creates a new FindOptions.

func (*FindOptions) AllowDiskUse

func (o *FindOptions) AllowDiskUse(v ...bool) *FindOptions

AllowDiskUse enables writing to temporary files.

func (*FindOptions) AllowPartialResults

func (o *FindOptions) AllowPartialResults(v ...bool) *FindOptions

AllowPartialResults specifies that a cursor should not error when some shards are unavailable.

func (*FindOptions) BatchSize

func (o *FindOptions) BatchSize(v int32) *FindOptions

BatchSize sets the number of documents to return in each batch.

func (*FindOptions) Collation

func (o *FindOptions) Collation(v *Collation) *FindOptions

Collation specifies a collation.

func (*FindOptions) Comment

func (o *FindOptions) Comment(v string) *FindOptions

Comment adds a comment to the query.

func (*FindOptions) CursorType

func (o *FindOptions) CursorType(v CursorType) *FindOptions

CursorType sets the type of cursor to use.

func (*FindOptions) Hint

func (o *FindOptions) Hint(v any) *FindOptions

Hint sets the index to use.

func (*FindOptions) Let

func (o *FindOptions) Let(v any) *FindOptions

Let specifies variables to use in the query.

func (*FindOptions) Limit

func (o *FindOptions) Limit(v int64) *FindOptions

Limit sets the limit for the query.

func (*FindOptions) Max

func (o *FindOptions) Max(v any) *FindOptions

Max specifies the exclusive upper bound for a specific index.

func (*FindOptions) MaxAwaitTime

func (o *FindOptions) MaxAwaitTime(v time.Duration) *FindOptions

MaxAwaitTime sets the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. This only applies when CursorType is set to CursorTailableAwait.

func (*FindOptions) MaxTime

func (o *FindOptions) MaxTime(v time.Duration) *FindOptions

MaxTime sets the maximum amount of time to allow the query to run.

func (*FindOptions) MaxTimeMS

func (o *FindOptions) MaxTimeMS(v time.Duration) *FindOptions

MaxTimeMS sets the maximum amount of time to allow the query to run.

func (*FindOptions) Min

func (o *FindOptions) Min(v any) *FindOptions

Min specifies the inclusive lower bound for a specific index.

func (*FindOptions) NoCursorTimeout

func (o *FindOptions) NoCursorTimeout(v ...bool) *FindOptions

NoCursorTimeout specifies that a cursor should not time out after a period of inactivity.

func (*FindOptions) OpLogReplay

func (o *FindOptions) OpLogReplay(v ...bool) *FindOptions

OpLogReplay specifies that a cursor should use the oplog for the query.

func (*FindOptions) Projection

func (o *FindOptions) Projection(v any) *FindOptions

Projection sets the fields to return for all matching documents.

func (*FindOptions) ReturnKey

func (o *FindOptions) ReturnKey(v ...bool) *FindOptions

ReturnKey specifies that a cursor should only return the index field or fields for the results.

func (*FindOptions) ShowRecordID

func (o *FindOptions) ShowRecordID(v ...bool) *FindOptions

ShowRecordID specifies that a cursor should return the record identifier for each document.

func (*FindOptions) Skip

func (o *FindOptions) Skip(v int64) *FindOptions

Skip sets the number of documents to skip before returning.

func (*FindOptions) Snapshot

func (o *FindOptions) Snapshot(v ...bool) *FindOptions

Snapshot specifies that a cursor should use a snapshot for the query.

func (*FindOptions) Sort

func (o *FindOptions) Sort(v any) *FindOptions

Sort sets the order in which to return matching documents.

type FindResult

type FindResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
}

type FullDocument

type FullDocument string

FullDocument specifies how a change stream should return the modified document.

const (
	// FullDocumentDefault does not include a document copy.
	FullDocumentDefault FullDocument = "default"
	// FullDocumentOff is the same as sending no value for fullDocumentBeforeChange.
	FullDocumentOff FullDocument = "off"
	// FullDocumentRequired is the same as WhenAvailable but raises a server-side error if the post-image is not available.
	FullDocumentRequired FullDocument = "required"
	// FullDocumentUpdateLookup includes a delta describing the changes to the document and a copy of the entire document that
	// was changed.
	FullDocumentUpdateLookup FullDocument = "updateLookup"
	// FullDocumentWhenAvailable includes a post-image of the the modified document for replace and update change events
	// if the post-image for this event is available.
	FullDocumentWhenAvailable FullDocument = "whenAvailable"
)

type GetOptions

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

GetOptions is a wrapper around mongo options.

func NewGetOptions

func NewGetOptions() *GetOptions

NewGetOptions creates a new GetOptions.

func (*GetOptions) AllowPartialResults

func (o *GetOptions) AllowPartialResults(v ...bool) *GetOptions

AllowPartialResults specifies whether to allow partial results if some shards are

func (*GetOptions) BatchSize

func (o *GetOptions) BatchSize(v int32) *GetOptions

BatchSize specifies the maximum number of documents to return in the batch.

func (*GetOptions) Collation

func (o *GetOptions) Collation(v *Collation) *GetOptions

Collation specifies a collation.

func (*GetOptions) Comment

func (o *GetOptions) Comment(v string) *GetOptions

Comment specifies a string to help trace the operation through the database profiler, currentOp and logs.

func (*GetOptions) Hint

func (o *GetOptions) Hint(v any) *GetOptions

Hint specifies the index to use.

func (*GetOptions) Max

func (o *GetOptions) Max(v any) *GetOptions

Max specifies the exclusive upper bound for a specific index.

func (*GetOptions) MaxTime

func (o *GetOptions) MaxTime(v time.Duration) *GetOptions

MaxTime specifies the maximum amount of time to allow the query to run.

func (*GetOptions) Min

func (o *GetOptions) Min(v any) *GetOptions

Min specifies the inclusive lower bound for a specific index.

func (*GetOptions) NoCursorTimeout

func (o *GetOptions) NoCursorTimeout(v ...bool) *GetOptions

NoCursorTimeout specifies whether to allow the cursor to timeout.

func (*GetOptions) OplogReplay

func (o *GetOptions) OplogReplay(v ...bool) *GetOptions

OplogReplay specifies whether to allow the cursor to timeout.

func (*GetOptions) Projection

func (o *GetOptions) Projection(v any) *GetOptions

Projection specifies the fields to return.

func (*GetOptions) ReturnKey

func (o *GetOptions) ReturnKey(v ...bool) *GetOptions

ReturnKey specifies whether to only return the index keys in the resulting documents.

func (*GetOptions) ShowRecordID

func (o *GetOptions) ShowRecordID(v ...bool) *GetOptions

ShowRecordID specifies whether to add a record identifier for each document.

func (*GetOptions) Skip

func (o *GetOptions) Skip(v int64) *GetOptions

Skip specifies the number of documents to skip before returning.

func (*GetOptions) Snapshot

func (o *GetOptions) Snapshot(v ...bool) *GetOptions

Snapshot specifies whether to prevent the cursor from returning a document more than once because of an intervening write operation.

func (*GetOptions) Sort

func (o *GetOptions) Sort(v any) *GetOptions

Sort specifies the order in which to return results.

type IndexModel

type IndexModel struct {
	// Keys is a document that contains the index keys and their corresponding sort order.
	Keys any

	Options *IndexOptions
}

IndexModel is a model for an index to create.

func NewIndexModel

func NewIndexModel(keys any, options ...*IndexOptions) IndexModel

NewIndexModel creates a new IndexModel.

type IndexOptions

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

IndexOptions is a wrapper around mongo options.

func NewIndexOptions

func NewIndexOptions() *IndexOptions

NewIndexOptions creates a new IndexOptions.

func (*IndexOptions) Background

func (o *IndexOptions) Background(v ...bool) *IndexOptions

Background specifies whether the index should be built in the background.

func (*IndexOptions) Bits

func (o *IndexOptions) Bits(v int32) *IndexOptions

Bits specifies the number of precision of the stored geohash value of the 2d index.

func (*IndexOptions) BucketSize

func (o *IndexOptions) BucketSize(v int32) *IndexOptions

BucketSize specifies the number of units within which to group the location values for the geoHaystack index.

func (*IndexOptions) Collation

func (o *IndexOptions) Collation(v *options.Collation) *IndexOptions

Collation specifies a collation.

func (*IndexOptions) DefaultLanguage

func (o *IndexOptions) DefaultLanguage(v string) *IndexOptions

DefaultLanguage specifies the default language for the index.

func (*IndexOptions) ExpireAfterSeconds

func (o *IndexOptions) ExpireAfterSeconds(v int32) *IndexOptions

ExpireAfterSeconds specifies the number of seconds after which documents in the collection should expire.

func (*IndexOptions) Hidden

func (o *IndexOptions) Hidden(v ...bool) *IndexOptions

Hidden specifies whether the index should be hidden.

func (*IndexOptions) LanguageOverride

func (o *IndexOptions) LanguageOverride(v string) *IndexOptions

LanguageOverride specifies the field in the document that contains the override language for the index.

func (*IndexOptions) Max

func (o *IndexOptions) Max(v float64) *IndexOptions

Max specifies the upper inclusive boundary for the longitude and latitude values for the 2d index.

func (*IndexOptions) Min

func (o *IndexOptions) Min(v float64) *IndexOptions

Min specifies the lower inclusive boundary for the longitude and latitude values for the 2d index.

func (*IndexOptions) Name

func (o *IndexOptions) Name(v string) *IndexOptions

Name specifies the name of the index.

func (*IndexOptions) PartialFilterExpression

func (o *IndexOptions) PartialFilterExpression(v any) *IndexOptions

PartialFilterExpression specifies a filter document that determines which documents in the collection should be included in the index.

func (*IndexOptions) Sparse

func (o *IndexOptions) Sparse(v ...bool) *IndexOptions

Sparse specifies whether the index only references documents with the specified field.

func (*IndexOptions) SphereVersion

func (o *IndexOptions) SphereVersion(v int32) *IndexOptions

SphereVersion specifies the version of the 2dsphere index.

func (*IndexOptions) StorageEngine

func (o *IndexOptions) StorageEngine(v any) *IndexOptions

StorageEngine specifies storage engine options for the index.

func (*IndexOptions) TextVersion

func (o *IndexOptions) TextVersion(v int32) *IndexOptions

TextVersion specifies the version of the text index.

func (*IndexOptions) Unique

func (o *IndexOptions) Unique(v ...bool) *IndexOptions

Unique specifies whether the index should enforce a unique constraint on the indexed field.

func (*IndexOptions) Version

func (o *IndexOptions) Version(v int32) *IndexOptions

Version specifies the version number of the index.

func (*IndexOptions) Weights

func (o *IndexOptions) Weights(v any) *IndexOptions

Weights specifies the weight for each field in the index.

func (*IndexOptions) WildcardProjection

func (o *IndexOptions) WildcardProjection(v any) *IndexOptions

WildcardProjection specifies a document that contains a field and its associated wildcard projection.

type InsertManyOptions

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

InsertManyOptions is a wrapper around mongo options.

func NewInsertManyOptions

func NewInsertManyOptions() *InsertManyOptions

NewInsertManyOptions creates a new InsertManyOptions.

func (*InsertManyOptions) BypassDocumentValidation

func (o *InsertManyOptions) BypassDocumentValidation(v ...bool) *InsertManyOptions

BypassDocumentValidation specifies whether to bypass document validation during the insert operation.

func (*InsertManyOptions) Comment

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*InsertManyOptions) Ordered

func (o *InsertManyOptions) Ordered(v ...bool) *InsertManyOptions

Ordered specifies whether the operations in the bulk write should be executed in order.

type InsertManyResult

type InsertManyResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// InsertedIDs is the _id fields of the inserted documents, or nil if no documents were inserted.
	InsertedIDs []any
}

type InsertOneOptions

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

InsertOneOptions is a wrapper around mongo options.

func NewInsertOneOptions

func NewInsertOneOptions() *InsertOneOptions

NewInsertOneOptions creates a new InsertOneOptions.

func (*InsertOneOptions) BypassDocumentValidation

func (o *InsertOneOptions) BypassDocumentValidation(v ...bool) *InsertOneOptions

BypassDocumentValidation specifies whether to bypass document validation during the insert operation.

func (*InsertOneOptions) Comment

func (o *InsertOneOptions) Comment(v string) *InsertOneOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

type InsertResult

type InsertResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// InsertedID is the _id field of the inserted document, or nil if no document was inserted.
	InsertedID any
}

type ListCollectionsOptions

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

func NewListCollectionsOptions

func NewListCollectionsOptions() *ListCollectionsOptions

func (*ListCollectionsOptions) AuthorizedCollections

func (o *ListCollectionsOptions) AuthorizedCollections(v bool) *ListCollectionsOptions

AuthorizedCollections specifies whether to limit the documents returned to only contain collections the user is authorized to use.

func (*ListCollectionsOptions) BatchSize

BatchSize specifies the maximum number of documents to be included in each batch returned by the server.

func (*ListCollectionsOptions) NameOnly

NameOnly specifies whether to limit the documents returned to only contain the name of the collection.

type ListCollectionsResult

type ListCollectionsResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error

	// Names is the names of the collections returned by the operation.
	Names []string
}

type ListIndexesOptions

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

ListIndexesOptions is a wrapper around mongo options.

func NewListIndexesOptions

func NewListIndexesOptions() *ListIndexesOptions

NewListIndexesOptions creates a new ListIndexesOptions.

func (*ListIndexesOptions) BatchSize

func (o *ListIndexesOptions) BatchSize(v int32) *ListIndexesOptions

BatchSize specifies the maximum number of documents to return in each batch of the returned cursor.

func (*ListIndexesOptions) MaxTime

MaxTime specifies the maximum amount of time to allow the query to run.

type ListIndexesResult

type ListIndexesResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
}

type M

type M = bson.M

type Options

type Options[T any] interface {
	// contains filtered or unexported methods
}

Options is a wrapper around mongo options.

type ReplaceOptions

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

ReplaceOptions is a wrapper around mongo options.

func NewReplaceOptions

func NewReplaceOptions() *ReplaceOptions

NewReplaceOptions creates a new ReplaceOptions.

func (*ReplaceOptions) BypassDocumentValidation

func (o *ReplaceOptions) BypassDocumentValidation(v ...bool) *ReplaceOptions

BypassDocumentValidation specifies whether to bypass document validation during the replace operation.

func (*ReplaceOptions) Collation

func (o *ReplaceOptions) Collation(v *options.Collation) *ReplaceOptions

Collation specifies a collation.

func (*ReplaceOptions) Comment

func (o *ReplaceOptions) Comment(v string) *ReplaceOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*ReplaceOptions) Hint

func (o *ReplaceOptions) Hint(v any) *ReplaceOptions

Hint specifies the index to use.

func (*ReplaceOptions) Let

func (o *ReplaceOptions) Let(v any) *ReplaceOptions

Let specifies variables accessible from the replace expression.

func (*ReplaceOptions) Upsert

func (o *ReplaceOptions) Upsert(v ...bool) *ReplaceOptions

Upsert specifies whether to insert a new document if no documents match the filter.

type ReturnDocument

type ReturnDocument int32

type SingleResult

type SingleResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
}

func (*SingleResult) IsNotFound

func (r *SingleResult) IsNotFound() bool

type Timestamp

type Timestamp primitive.Timestamp

type TransactionOptions

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

TransactionOptions is a wrapper around mongo transaction options.

func NewTransactionOptions

func NewTransactionOptions() *TransactionOptions

NewTransactionOptions creates a new TransactionOptions.

func (*TransactionOptions) MaxCommitTime

func (o *TransactionOptions) MaxCommitTime(v *time.Duration) *TransactionOptions

MaxCommitTime specifies the maximum amount of time that a CommitTransaction operation can run on the server.

func (*TransactionOptions) ReadConcern

ReadConcern specifies the read concern for the transaction.

func (*TransactionOptions) ReadPref

ReadPref specifies the read preference for the transaction.

func (*TransactionOptions) WriteConcern

WriteConcern specifies the write concern for the transaction.

type UpdateOptions

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

UpdateOptions is a wrapper around mongo options.

func NewUpdateOptions

func NewUpdateOptions() *UpdateOptions

NewUpdateOptions creates a new UpdateOptions.

func (*UpdateOptions) ArrayFilters

func (o *UpdateOptions) ArrayFilters(v ArrayFilters) *UpdateOptions

ArrayFilters specifies an array of filters specifying to which array elements an update should apply.

func (*UpdateOptions) BypassDocumentValidation

func (o *UpdateOptions) BypassDocumentValidation(v ...bool) *UpdateOptions

BypassDocumentValidation specifies whether to bypass document validation during the update operation.

func (*UpdateOptions) Collation

func (o *UpdateOptions) Collation(v Collation) *UpdateOptions

Collation specifies a collation.

func (*UpdateOptions) Comment

func (o *UpdateOptions) Comment(v string) *UpdateOptions

Comment specifies a string or document that will be included in server logs, profiling logs, and currentOp queries to help trace the operation. The default value is nil, which means that no comment will be included in the logs.

func (*UpdateOptions) Hint

func (o *UpdateOptions) Hint(v any) *UpdateOptions

Hint specifies the index to use. The default value is nil, which means that no hint will be sent.

func (*UpdateOptions) Let

func (o *UpdateOptions) Let(v any) *UpdateOptions

Let specifies variables accessible from the update expression.

func (*UpdateOptions) Upsert

func (o *UpdateOptions) Upsert(v ...bool) *UpdateOptions

Upsert specifies whether to insert a new document if no documents match the filter.

type UpdateResult

type UpdateResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// MatchedCount is the number of documents matched by the filter.
	MatchedCount int64
	// ModifiedCount is the number of documents modified by the operation.
	ModifiedCount int64
	// UpsertedCount is the number of documents upserted by the operation.
	UpsertedCount int64
	// UpsertedID is the _id of the upserted document, or nil if no document was upserted.
	UpsertedID any
}

type WatchOptions

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

WatchOptions is a wrapper around mongo options.

func NewWatchOptions

func NewWatchOptions() *WatchOptions

NewWatchOptions creates a new WatchOptions.

func (*WatchOptions) BatchSize

func (o *WatchOptions) BatchSize(v int32) *WatchOptions

BatchSize sets the number of documents to return in each batch.

func (*WatchOptions) Collation

func (o *WatchOptions) Collation(v Collation) *WatchOptions

Collation specifies a collation.

func (*WatchOptions) Comment

func (o *WatchOptions) Comment(v string) *WatchOptions

Comment adds a comment to the query.

func (*WatchOptions) Custom

func (o *WatchOptions) Custom(v bson.M) *WatchOptions

Custom ...

func (*WatchOptions) CustomPipeline

func (o *WatchOptions) CustomPipeline(v bson.M) *WatchOptions

CustomPipeline ...

func (*WatchOptions) FullDocument

func (o *WatchOptions) FullDocument(v FullDocument) *WatchOptions

FullDocument specifies whether to return the full document or just the changes to the document.

func (*WatchOptions) FullDocumentBeforeChange

func (o *WatchOptions) FullDocumentBeforeChange(v FullDocument) *WatchOptions

FullDocumentBeforeChange specifies whether to return the full document before the change occurred.

func (*WatchOptions) MaxAwaitTime

func (o *WatchOptions) MaxAwaitTime(v time.Duration) *WatchOptions

MaxAwaitTime specifies the maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. This only applies to tailable cursor queries issued against a replica set. The default value is nil, which means that there is no maximum await time.

func (*WatchOptions) ResumeAfter

func (o *WatchOptions) ResumeAfter(v any) *WatchOptions

ResumeAfter specifies the logical starting point for the new change stream.

func (*WatchOptions) ShowExpandedEvents

func (o *WatchOptions) ShowExpandedEvents(v ...bool) *WatchOptions

ShowExpandedEvents specifies whether to include the postImage field in update notifications.

func (*WatchOptions) StartAfter

func (o *WatchOptions) StartAfter(v any) *WatchOptions

StartAfter specifies the logical starting point for the new change stream.

func (*WatchOptions) StartAtOperationTime

func (o *WatchOptions) StartAtOperationTime(v *Timestamp) *WatchOptions

StartAtOperationTime specifies a logical starting point for the new change stream.

type WatchResult

type WatchResult struct {
	// Err is the error that occurred during the operation, if any.
	Err error
	// contains filtered or unexported fields
}

func (*WatchResult) Get

func (r *WatchResult) Get(v any) error

Jump to

Keyboard shortcuts

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