Documentation
¶
Index ¶
- type Client
- type ClientConfig
- type Collection
- func (c *Collection) Aggregate(pipeline interface{}) ([]interface{}, error)
- func (c *Collection) Collection() *mgo.Collection
- func (c *Collection) DeleteMany(filter interface{}) (*mgo.DeleteResult, error)
- func (c *Collection) Find(filter interface{}, opts ...findopt.Find) ([]interface{}, error)
- func (c *Collection) FindOne(filter interface{}, opts ...findopt.One) (interface{}, error)
- func (c *Collection) InsertMany(data []interface{}) (*[]mgo.InsertOneResult, error)
- func (c *Collection) InsertOne(data interface{}) (*mgo.InsertOneResult, error)
- func (c *Collection) UpdateMany(filter interface{}, update interface{}) (*mgo.UpdateResult, error)
- type ConnectionConfig
- type IndexColumnConfig
- type IndexConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a MongoDB client. This wraps the Mongo-Go-Driver client.
func NewClient ¶
func NewClient(config ClientConfig) (*Client, error)
NewClient creates new client based on the ClientConfig provided.
func (*Client) Connect ¶
Connect connects the created client to Database. This is a no-op if the client is already connected. This is also run by default unless "NoDefaultConnect" is specified in ClientConfig.
func (*Client) Disconnect ¶
Disconnect disconnects the created client from Database. This is a no-op if the client is already disconnected.
func (*Client) DriverClient ¶
DriverClient returns the wrapped Mongo-Go-Driver client.
type ClientConfig ¶
type ClientConfig struct { Hosts []string Username string Password string NoDefaultConnect bool TimeoutMilliseconds uint32 }
ClientConfig represents the configuration for a client.
type Collection ¶
type Collection struct { Connection *ConnectionConfig Database string Name string // Indexes to be created when creating collection Indexes []IndexConfig SchemaStruct interface{} // contains filtered or unexported fields }
Collection represents the MongoDB collection.
func EnsureCollection ¶
func EnsureCollection(c *Collection) (*Collection, error)
EnsureCollection creates new collection with the provided indexes. If the collection already exists, it will just return the existing collection.
func (*Collection) Aggregate ¶ added in v1.5.0
func (c *Collection) Aggregate(pipeline interface{}) ([]interface{}, error)
Aggregate runs an aggregation framework pipeline See https://docs.mongodb.com/manual/aggregation/.
func (*Collection) Collection ¶
func (c *Collection) Collection() *mgo.Collection
Collection returns the embedded Mongo-Go-Driver Collection. Use this only when absolutely required, and prefer inbuilt functions over functions from this.
func (*Collection) DeleteMany ¶
func (c *Collection) DeleteMany(filter interface{}) (*mgo.DeleteResult, error)
DeleteMany deletes multiple documents from the collection. The filter-data must match the schema provided at the time of Collection- creation. Update the Collection.SchemaStruct if new schema is required.
func (*Collection) Find ¶
func (c *Collection) Find( filter interface{}, opts ...findopt.Find, ) ([]interface{}, error)
Find finds the documents matching the filter. The filter-data must match the schema provided at the time of Collection- creation. Update the Collection.SchemaStruct if new schema is required. A map can also be provided as filter. For example, a find-query in MongoDB such as:
{hits: {$gt: 4, $lt: 9}}
can be represented in a map as:
map[string]interface{}{ "hits": map[string]interface{ "$gt": 4, "$lt": 9, }, }
func (*Collection) FindOne ¶
func (c *Collection) FindOne( filter interface{}, opts ...findopt.One, ) (interface{}, error)
FindOne returns single result that matches the provided filter. The filter-data must match the schema provided at the time of Collection- creation. Update the Collection.SchemaStruct if new schema is required.
func (*Collection) InsertMany ¶
func (c *Collection) InsertMany( data []interface{}, ) (*[]mgo.InsertOneResult, error)
InsertMany inserts the provided data into Collection. 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. The data must match the schema provided at the time of Collection- creation. Update the Collection.SchemaStruct if new schema is required.
func (*Collection) InsertOne ¶
func (c *Collection) InsertOne(data interface{}) (*mgo.InsertOneResult, error)
InsertOne inserts the provided data into Collection. The data must match the schema provided at the time of Collection- creation. Update the Collection.SchemaStruct if new schema is required.
func (*Collection) UpdateMany ¶
func (c *Collection) UpdateMany( filter interface{}, update interface{}, ) (*mgo.UpdateResult, error)
UpdateMany updates multiple documents in the collection. A map or a struct can be supplied as filter-data or update-data, both are transformed into BSON using bson#NewDocumentEncoder#EncodeDocument.
type ConnectionConfig ¶
ConnectionConfig defines the Client to use for communicating with MongoDB, and the Timeout for that client.
type IndexColumnConfig ¶
IndexColumnConfig defines configuration for a column in index-definition.
type IndexConfig ¶
type IndexConfig struct { ColumnConfig []IndexColumnConfig IsUnique bool Name string }
IndexConfig defines configuration for indexes to be created when creating this collection.