Documentation ¶
Overview ¶
Package db manages Evergreen's interaction with the database.
Index ¶
- Constants
- Variables
- func Aggregate(collection string, pipeline interface{}, out interface{}) error
- func AggregateWithMaxTime(collection string, pipeline interface{}, out interface{}, ...) error
- func Clear(collection string) error
- func ClearCollections(collections ...string) error
- func ClearGridCollections(fsPrefix string) error
- func Count(collection string, query interface{}) (int, error)
- func CountQ(collection string, q Q) (int, error)
- func CreateCollections(collections ...string) error
- func DropCollections(collections ...string) error
- func EnsureIndex(collection string, index mongo.IndexModel) error
- func FindAllQ(collection string, q Q, out interface{}) error
- func FindAndModify(collection string, query interface{}, sort []string, change db.Change, ...) (*db.ChangeInfo, error)
- func FindOneQ(collection string, q Q, out interface{}) error
- func GetGridFile(fsPrefix, name string) (io.ReadCloser, error)
- func Insert(collection string, item interface{}) error
- func InsertMany(collection string, items ...interface{}) error
- func InsertManyUnordered(c string, items ...interface{}) error
- func IsDocumentLimit(err error) bool
- func IsDuplicateKey(err error) bool
- func IsErrorCode(err error, errorCode int) bool
- func Remove(collection string, query interface{}) error
- func RemoveAll(collection string, query interface{}) error
- func RemoveAllQ(collection string, q Q) error
- func Update(collection string, query interface{}, update interface{}) error
- func UpdateAll(collection string, query interface{}, update interface{}) (*db.ChangeInfo, error)
- func UpdateId(collection string, id, update interface{}) error
- func Upsert(collection string, query interface{}, update interface{}) (*db.ChangeInfo, error)
- func WriteGridFile(fsPrefix, name string, source io.Reader) error
- type Q
- func (q Q) Filter(filter interface{}) Q
- func (q Q) GetBSON() (interface{}, error)
- func (q Q) Hint(hint interface{}) Q
- func (q Q) Limit(limit int) Q
- func (q Q) MarshalBSON() ([]byte, error)
- func (q Q) MaxTime(maxTime time.Duration) Q
- func (q Q) Project(projection interface{}) Q
- func (q Q) SetBSON(_ bson.Raw) error
- func (q Q) Skip(skip int) Q
- func (q Q) Sort(sort []string) Q
- func (q Q) UnmarshalBSON(_ []byte) error
- func (q Q) WithFields(fields ...string) Q
- func (q Q) WithoutFields(fields ...string) Q
- type SessionFactory
Constants ¶
const FacetPipelineStageTooLargeCode = 4031700
FacetPipelineStageTooLargeCode is the error code for when a facet pipeline stage is too large. https://github.com/mongodb/mongo/blob/a1732172ed5d66d98582ea1059c0ede9d8cd5065/src/mongo/db/pipeline/document_source_facet.cpp#L165
Variables ¶
var ( NoProjection = bson.M{} NoSort = []string{} NoSkip = 0 NoLimit = 0 NoHint interface{} = nil )
Functions ¶
func Aggregate ¶
Aggregate runs an aggregation pipeline on a collection and unmarshals the results to the given "out" interface (usually a pointer to an array of structs/bson.M)
func AggregateWithMaxTime ¶
func AggregateWithMaxTime(collection string, pipeline interface{}, out interface{}, maxTime time.Duration) error
AggregateWithMaxTime runs aggregate and specifies a max query time which ensures the query won't go on indefinitely when the request is cancelled.
func ClearCollections ¶
ClearCollections clears all documents from all the specified collections, returning an error immediately if clearing any one of them fails.
func ClearGridCollections ¶
func CreateCollections ¶
CreateCollections ensures that all the given collections are created, returning an error immediately if creating any one of them fails.
func DropCollections ¶
DropCollections drops the specified collections, returning an error immediately if dropping any one of them fails.
func EnsureIndex ¶
func EnsureIndex(collection string, index mongo.IndexModel) error
EnsureIndex takes in a collection and ensures that the index is created if it does not already exist.
func FindAllQ ¶
FindAllQ runs a Q query against the given collection, applying the results to "out."
func FindAndModify ¶
func FindAndModify(collection string, query interface{}, sort []string, change db.Change, out interface{}) (*db.ChangeInfo, error)
FindAndModify runs the specified query and change against the collection, unmarshaling the result into the specified interface.
func FindOneQ ¶
FindOneQ runs a Q query against the given collection, applying the results to "out." Only reads one document from the DB.
func GetGridFile ¶
func GetGridFile(fsPrefix, name string) (io.ReadCloser, error)
GetGridFile returns a ReadCloser for a file stored with the given name under the GridFS prefix.
func InsertMany ¶
func InsertManyUnordered ¶
func IsDocumentLimit ¶
func IsDuplicateKey ¶
func IsErrorCode ¶
IsErrorCode checks if the error is a mongo error with the given error code.
func RemoveAllQ ¶
RemoveAllQ removes all docs that satisfy the query
func UpdateAll ¶
func UpdateAll(collection string, query interface{}, update interface{}) (*db.ChangeInfo, error)
UpdateAll updates all matching documents in the collection.
Types ¶
type Q ¶
type Q struct {
// contains filtered or unexported fields
}
Q holds all information necessary to execute a query
func Query ¶
func Query(filter interface{}) Q
Query creates a db.Q for the given MongoDB query. The filter can be a struct, bson.D, bson.M, nil, etc.
func (Q) Hint ¶
Hint sets the hint for a query to determine what index will be used. The hint can be either the index as an ordered document of the keys or a
func (Q) MarshalBSON ¶
func (Q) UnmarshalBSON ¶
func (Q) WithFields ¶
func (Q) WithoutFields ¶
type SessionFactory ¶
type SessionFactory interface { // GetSession uses the global environment's context to get a session and database. GetSession() (db.Session, db.Database, error) // GetContextSession uses the provided context to get a session and database. // This is needed for operations that need control over the passed-in context. // TODO DEVPROD-11824 Use this method instead of GetSession. GetContextSession(ctx context.Context) (db.Session, db.Database, error) }
func GetGlobalSessionFactory ¶
func GetGlobalSessionFactory() SessionFactory
Directories ¶
Path | Synopsis |
---|---|
Package mgo provides support for Evergreen's remaining usages of the legacy MongoDB driver gopkg.in/mgo.v2.
|
Package mgo provides support for Evergreen's remaining usages of the legacy MongoDB driver gopkg.in/mgo.v2. |
bson
Package bson is an implementation of the BSON specification for Go:
|
Package bson is an implementation of the BSON specification for Go: |
internal/json
Package json implements encoding and decoding of JSON as defined in RFC 4627.
|
Package json implements encoding and decoding of JSON as defined in RFC 4627. |