Documentation ¶
Index ¶
- Constants
- func HasRemovedRecords(deleteResult *CollectionDeleteResult) bool
- func HasUpdatedOrUpserted(updateResult *CollectionUpdateResult) bool
- func IsErrNoDocumentFound(err error) bool
- func IsServerErr(err error) bool
- func NewErrNoDocumentFoundError(msg string, err error) error
- func WithLastUpdatedUpdate(updateDoc bson.M) (bson.M, error)
- func WithNamespacedLastUpdatedUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)
- func WithNamespacedUniqueTimestampQuery(queryDoc bson.M, timestamps []primitive.Timestamp, prefixes []string) bson.M
- func WithNamespacedUniqueTimestampUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)
- func WithNamespacedUpdates(updateDoc bson.M, prefixes []string) (bson.M, error)
- func WithUniqueTimestampQuery(queryDoc bson.M, timestamp primitive.Timestamp) bson.M
- func WithUniqueTimestampUpdate(updateDoc bson.M) (bson.M, error)
- func WithUpdates(updateDoc bson.M) (bson.M, error)
- type Collection
- func (c *Collection) Aggregate(pipeline interface{}) *Cursor
- func (c *Collection) Find(query interface{}) *Find
- func (c *Collection) FindOne(ctx context.Context, filter interface{}, result interface{}) error
- func (c *Collection) Insert(ctx context.Context, documents []interface{}) (*CollectionInsertResult, error)
- func (c *Collection) InsertOne(ctx context.Context, document interface{}) (*CollectionInsertOneResult, error)
- func (c *Collection) Must() *Must
- func (c *Collection) Remove(ctx context.Context, selector interface{}) (*CollectionDeleteResult, error)
- func (c *Collection) RemoveId(ctx context.Context, id interface{}) (*CollectionDeleteResult, error)
- func (c *Collection) Update(ctx context.Context, selector interface{}, update interface{}) (*CollectionUpdateResult, error)
- func (c *Collection) UpdateId(ctx context.Context, id interface{}, update interface{}) (*CollectionUpdateResult, error)
- func (c *Collection) Upsert(ctx context.Context, selector interface{}, update interface{}) (*CollectionUpdateResult, error)
- func (c *Collection) UpsertId(ctx context.Context, id interface{}, update interface{}) (*CollectionUpdateResult, error)
- type CollectionDeleteResult
- type CollectionInsertOneResult
- type CollectionInsertResult
- type CollectionUpdateResult
- type CreateAggregateCursor
- type CreateCursor
- type CreateFindCursor
- type Cursor
- type ErrDisconnect
- type ErrNoDocumentFound
- type ErrServerError
- type ErrTimeout
- type Find
- func (find *Find) Count(ctx context.Context) (int, error)
- func (find *Find) Distinct(ctx context.Context, fieldName string) ([]interface{}, error)
- func (find *Find) Find(query interface{}) *Find
- func (find *Find) Iter() *Cursor
- func (find *Find) IterAll(ctx context.Context, results interface{}) error
- func (find *Find) Limit(limit int) *Find
- func (find *Find) One(ctx context.Context, val interface{}) error
- func (find *Find) Select(projection interface{}) *Find
- func (find *Find) Skip(skip int) *Find
- func (find *Find) Sort(sort interface{}) *Find
- type Graceful
- type MongoConnection
- func (ms *MongoConnection) C(collection string) *Collection
- func (ms *MongoConnection) Close(ctx context.Context) error
- func (ms *MongoConnection) DropDatabase(ctx context.Context) error
- func (ms *MongoConnection) GetConfiguredCollection() *Collection
- func (ms *MongoConnection) GetMongoCollection() *mongo.Collection
- func (ms *MongoConnection) ListCollectionsFor(ctx context.Context, database string) ([]string, error)
- func (ms *MongoConnection) Ping(ctx context.Context, timeoutInSeconds time.Duration) error
- type MongoConnectionConfig
- type MongoConnector
- type MongoError
- type Must
- func (m *Must) Remove(ctx context.Context, selector interface{}) (*CollectionDeleteResult, error)
- func (m *Must) RemoveId(ctx context.Context, id interface{}) (*CollectionDeleteResult, error)
- func (m *Must) Update(ctx context.Context, selector interface{}, update interface{}) (*CollectionUpdateResult, error)
- func (m *Must) UpdateId(ctx context.Context, id interface{}, update interface{}) (*CollectionUpdateResult, error)
- type Timestamps
Constants ¶
const ( LastUpdatedKey = "last_updated" UniqueTimestampKey = "unique_timestamp" )
keep these in sync with Timestamps tags below
Variables ¶
This section is empty.
Functions ¶
func HasRemovedRecords ¶
func HasRemovedRecords(deleteResult *CollectionDeleteResult) bool
returns true if a remove operation has remove at least one record
func HasUpdatedOrUpserted ¶
func HasUpdatedOrUpserted(updateResult *CollectionUpdateResult) bool
returns true if a update operation updated or upserted a record
func IsErrNoDocumentFound ¶
func IsServerErr ¶
func WithLastUpdatedUpdate ¶
WithLastUpdatedUpdate adds last_updated to updateDoc
func WithNamespacedLastUpdatedUpdate ¶
func WithNamespacedLastUpdatedUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)
WithNamespacedLastUpdatedUpdate adds unique timestamp to updateDoc
func WithNamespacedUniqueTimestampQuery ¶
func WithNamespacedUniqueTimestampQuery(queryDoc bson.M, timestamps []primitive.Timestamp, prefixes []string) bson.M
WithNamespacedUniqueTimestampQuery adds unique timestamps to queryDoc sub-docs
func WithNamespacedUniqueTimestampUpdate ¶
func WithNamespacedUniqueTimestampUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)
WithNamespacedUniqueTimestampUpdate adds unique timestamp to updateDoc
func WithNamespacedUpdates ¶
WithNamespacedUpdates adds all timestamps to updateDoc
func WithUniqueTimestampQuery ¶
WithUniqueTimestampQuery adds unique timestamp to queryDoc
func WithUniqueTimestampUpdate ¶
WithUniqueTimestampUpdate adds unique timestamp to updateDoc
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
func NewCollection ¶
func NewCollection(collection *mongo.Collection) *Collection
func (*Collection) Aggregate ¶
func (c *Collection) Aggregate(pipeline interface{}) *Cursor
Aggreate start a pipeline operation
func (*Collection) Find ¶
func (c *Collection) Find(query interface{}) *Find
Find returns a Find interface which can be used to either refine the criteria or retrieve a cursor
func (*Collection) FindOne ¶
func (c *Collection) FindOne(ctx context.Context, filter interface{}, result interface{}) error
FindOne locates a single document
func (*Collection) Insert ¶
func (c *Collection) Insert(ctx context.Context, documents []interface{}) (*CollectionInsertResult, error)
Insert adds a number of documents
func (*Collection) InsertOne ¶
func (c *Collection) InsertOne(ctx context.Context, document interface{}) (*CollectionInsertOneResult, error)
InsertOne creates a single record
func (*Collection) Must ¶
func (c *Collection) Must() *Must
func (*Collection) Remove ¶
func (c *Collection) Remove(ctx context.Context, selector interface{}) (*CollectionDeleteResult, error)
Remove deletes records based on the provided selector
func (*Collection) RemoveId ¶
func (c *Collection) RemoveId(ctx context.Context, id interface{}) (*CollectionDeleteResult, error)
RemoveId deletes record based on the id selector
func (*Collection) Update ¶
func (c *Collection) Update(ctx context.Context, selector interface{}, update interface{}) (*CollectionUpdateResult, error)
Update modifies records located by a provided selector
func (*Collection) UpdateId ¶
func (c *Collection) UpdateId(ctx context.Context, id interface{}, update interface{}) (*CollectionUpdateResult, error)
UpdateId modifies records located by a provided Id selector
func (*Collection) Upsert ¶
func (c *Collection) Upsert(ctx context.Context, selector interface{}, update interface{}) (*CollectionUpdateResult, error)
Upsert creates or updates records located by a provided selector
func (*Collection) UpsertId ¶
func (c *Collection) UpsertId(ctx context.Context, id interface{}, update interface{}) (*CollectionUpdateResult, error)
UpsertId creates or updates records located by a provided Id selector
type CollectionDeleteResult ¶
type CollectionDeleteResult struct {
DeletedCount int // The number of records deleted
}
type CollectionInsertOneResult ¶
type CollectionInsertOneResult struct {
InsertedId interface{} // Id of the document inserted
}
CollectionInsertOneResult is the result type return from InsertOne
type CollectionInsertResult ¶
type CollectionInsertResult struct {
InsertedIds []interface{} // inserted Ids
}
CollectionInsertResult is the result type returned from Insert
type CollectionUpdateResult ¶
type CollectionUpdateResult struct { MatchedCount int // The number of documents matched by the filter. ModifiedCount int // The number of documents modified by the operation. UpsertedCount int // The number of documents upserted by the operation. UpsertedID interface{} // The _id field of the upserted document, or nil if no upsert was done. }
CollectionUpdateResult is the result type returned from UpdateOne, UpdateMany, and ReplaceOne operations.
type CreateAggregateCursor ¶
type CreateAggregateCursor struct {
// contains filtered or unexported fields
}
CreateAggreateCursor creates a cursor used with aggregation
type CreateCursor ¶
type CreateCursor interface {
// contains filtered or unexported methods
}
CreateCursor interface to create a unique cursor
type CreateFindCursor ¶
type CreateFindCursor struct {
// contains filtered or unexported fields
}
CreateFindCursor creates a find cursor
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
type ErrDisconnect ¶
type ErrDisconnect struct {
MongoError
}
type ErrNoDocumentFound ¶
type ErrNoDocumentFound struct {
MongoError
}
type ErrServerError ¶
type ErrServerError struct {
MongoError
}
type ErrTimeout ¶
type ErrTimeout struct {
MongoError
}
type Find ¶
type Find struct {
// contains filtered or unexported fields
}
func (*Find) IterAll ¶
IterAll return all the results for this query, you do not need to close the cursor after this call
func (*Find) One ¶
Find a record which matches the find criteria Current FindOptions are limited to what is used: Sort, Skip, Projection Other exhaustive list of options are: AllowPartialResults,BatchSize,Collation, Comment,CursorType,Hint,Max, MaxAwaitTime, MaxTime ,Min, NoCursorTimeout,OplogReplay,ReturnKey,ShowRecordID, Snapshot, ref: https://github.com/mongodb/mongo-go-driver/blob/master/mongo/options/findoptions.go#L306
type Graceful ¶
type Graceful interface {
// contains filtered or unexported methods
}
Graceful represents an interface to the shutdown method
type MongoConnection ¶
type MongoConnection struct {
// contains filtered or unexported fields
}
func NewMongoConnection ¶
func NewMongoConnection(client *mongo.Client, database string, collection string) *MongoConnection
func Open ¶
func Open(m *MongoConnectionConfig) (*MongoConnection, error)
func (*MongoConnection) C ¶
func (ms *MongoConnection) C(collection string) *Collection
func (*MongoConnection) Close ¶
func (ms *MongoConnection) Close(ctx context.Context) error
Close represents mongo session closing within the context deadline
func (*MongoConnection) DropDatabase ¶
func (ms *MongoConnection) DropDatabase(ctx context.Context) error
func (*MongoConnection) GetConfiguredCollection ¶
func (ms *MongoConnection) GetConfiguredCollection() *Collection
func (*MongoConnection) GetMongoCollection ¶
func (ms *MongoConnection) GetMongoCollection() *mongo.Collection
func (*MongoConnection) ListCollectionsFor ¶
type MongoConnectionConfig ¶
type MongoConnectionConfig struct { IsSSL bool ConnectTimeoutInSeconds time.Duration QueryTimeoutInSeconds time.Duration Username string Password string ClusterEndpoint string Database string Collection string ReplicaSet string IsStrongReadConcernEnabled bool IsWriteConcernMajorityEnabled bool }
func (*MongoConnectionConfig) GetConnectionURI ¶
func (m *MongoConnectionConfig) GetConnectionURI(isSSL bool) string
type MongoConnector ¶
type MongoConnector interface { Ping(ctx context.Context) error C(collection string) *Collection Close(ctx context.Context) error GetCollectionsFor(ctx context.Context, database string) ([]string, error) GetConfiguredCollection() *Collection GetMongoCollection() *mongo.Collection DropDatabase(ctx context.Context) error }
type MongoError ¶
func (*MongoError) Error ¶
func (m *MongoError) Error() string
func (*MongoError) Unwrap ¶
func (m *MongoError) Unwrap() error
type Must ¶
type Must struct {
// contains filtered or unexported fields
}
func (*Must) Remove ¶
func (m *Must) Remove(ctx context.Context, selector interface{}) (*CollectionDeleteResult, error)
Remove deletes records based on the provided selector, must delete at least one record
func (*Must) RemoveId ¶
func (m *Must) RemoveId(ctx context.Context, id interface{}) (*CollectionDeleteResult, error)
RemoveId deletes record based on the id selector must delete at least one record
type Timestamps ¶
type Timestamps struct { LastUpdated time.Time `bson:"last_updated,omitempty" json:"last_updated,omitempty"` UniqueTimestamp *primitive.Timestamp `bson:"unique_timestamp,omitempty" json:"-"` }
Timestamps represent an object containing time stamps keep these in sync with above const