Documentation ¶
Index ¶
- type Collection
- func (c *Collection) Count(filter bson.M) (uint64, error)
- func (c *Collection) Delete(filter bson.M) error
- func (c *Collection) DeleteByID(id primitive.ObjectID) error
- func (c *Collection) DeleteByIDs(ids ...primitive.ObjectID) error
- func (c *Collection) DeleteFirst(filter bson.M) error
- func (c *Collection) Dump(shouldPanicResults bool)
- func (c *Collection) Find(results any, filter bson.M) error
- func (c *Collection) FindCursor(filter bson.M) (*Cursor, error)
- func (c *Collection) FindFirst(placeInto any, filter bson.M) error
- func (c *Collection) Insert(documents ...any) error
- func (c *Collection) ReplaceFirst(filter bson.M, value any) error
- func (c *Collection) ReplaceFirstByID(id primitive.ObjectID, value any) error
- func (c *Collection) UnsafeInsert(documents ...any) error
- type Cursor
- type TestConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection contains all the data for a collection
func (*Collection) Count ¶
func (c *Collection) Count(filter bson.M) (uint64, error)
Count returns the number of documents in the collection of entity
func (*Collection) Delete ¶
func (c *Collection) Delete(filter bson.M) error
Delete deletes all documents matching the filter The query used here is {"_id": {"$in": ids}}
func (*Collection) DeleteByID ¶
func (c *Collection) DeleteByID(id primitive.ObjectID) error
DeleteByID deletes a document by it's ID The query used here is {"_id": id}
func (*Collection) DeleteByIDs ¶
func (c *Collection) DeleteByIDs(ids ...primitive.ObjectID) error
DeleteByIDs deletes documents by their IDs The query used here is {"_id": {"$in": ids}}
func (*Collection) DeleteFirst ¶
func (c *Collection) DeleteFirst(filter bson.M) error
DeleteFirst deletes the first document that matches the filter
func (*Collection) Dump ¶
func (c *Collection) Dump(shouldPanicResults bool)
DumpCollection prints a full database collection it's contents in the console This can be used in tests to dump the contents of the database might something fail or to debug
shouldPanic controls if the output is only printed or also should panic
func (*Collection) Find ¶
func (c *Collection) Find(results any, filter bson.M) error
Find finds documents in the collection of the base The results can be filtered using filters The filters should work equal to MongoDB filters (https://docs.mongodb.com/manual/tutorial/query-documents/) tough this might miss features compared to mongoDB's filters
func (*Collection) FindCursor ¶
func (c *Collection) FindCursor(filter bson.M) (*Cursor, error)
FindCursor finds documents in the collection of the base
func (*Collection) FindFirst ¶
func (c *Collection) FindFirst(placeInto any, filter bson.M) error
FindFirst finds the first document in the collection matching the filter and places it into placeInto The result can be filtered using filters The filters should work equal to MongoDB filters (https://docs.mongodb.com/manual/tutorial/query-documents/) tough this might miss features compared to mongoDB's filters
func (*Collection) Insert ¶
func (c *Collection) Insert(documents ...any) error
Insert inserts an item into the database Implements db.Connection
func (*Collection) ReplaceFirst ¶
func (c *Collection) ReplaceFirst(filter bson.M, value any) error
ReplaceFirst updates the first document in the database that matches the filter
func (*Collection) ReplaceFirstByID ¶
func (c *Collection) ReplaceFirstByID(id primitive.ObjectID, value any) error
ReplaceFirstByID updates a document in the database by its ID The query used here is {"_id": id}
func (*Collection) UnsafeInsert ¶
func (c *Collection) UnsafeInsert(documents ...any) error
UnsafeInsert inserts data directly into the database without locking it
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is a cursor for the testingdb implementing the db.Cursor
type TestConnection ¶
type TestConnection struct {
// contains filtered or unexported fields
}
TestConnection is the struct that implements db.Connection
func NewDB ¶
func NewDB() *TestConnection
NewDB returns a testing database connection that is compatible with db.Connection
func (*TestConnection) Collection ¶
func (c *TestConnection) Collection(name string) *Collection
func (*TestConnection) Dump ¶
func (c *TestConnection) Dump(shouldPanicResults bool)
Dump prints the full database contents in the console This can be used in tests to dump the contents of the database might something fail or to debug
shouldPanic controls if the output is only printed or also should panic