Documentation ¶
Overview ¶
Package mongodb provides MongoDB client implementations.
Index ¶
- type Client
- func (this *Client) DeleteMany(databaseName, collectionName string, filter any) error
- func (this *Client) DeleteOne(databaseName, collectionName string, filter any) error
- func (this *Client) Finalize() error
- func (this *Client) Find(databaseName, collectionName string, filter, dataForm any) (any, error)
- func (this *Client) FindOne(databaseName, collectionName string, filter any, dataForm any) (any, error)
- func (this *Client) Initialize(address string, timeout time.Duration) error
- func (this *Client) InsertMany(databaseName, collectionName string, documents []any) error
- func (this *Client) InsertOne(databaseName, collectionName string, document any) error
- func (this *Client) UpdateMany(databaseName, collectionName string, filter, update any) error
- func (this *Client) UpdateOne(databaseName, collectionName string, filter, update any) error
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 is a struct that provides client related methods.
func (*Client) DeleteMany ¶
DeleteMany is delete the values corresponding to the filter argument.
ex) err := client.DeleteMany("test_database", "test_collection", bson.M{})
func (*Client) DeleteOne ¶
DeleteOne is delete one value corresponding to the filter argument.
ex) err := client.DeleteOne("test_database", "test_collection", bson.M{"value1": 1})
func (*Client) Find ¶
"Find" is returns results value corresponding to the filter argument as an "dataForm" argument array type interface.
ex)
results_interface, err := client.Find("test_database", "test_collection", bson.M{}, TestStruct{}) results, ok := results_interface.([]TestStruct)
func (*Client) FindOne ¶
func (this *Client) FindOne(databaseName, collectionName string, filter any, dataForm any) (any, error)
"FindOne" is returns one result value corresponding to the filter argument as an "dataForm" argument type interface.
ex) result_interface, err := client.FindOne("test_database", "test_collection", bson.M{"value1": 1}, TestStruct{}) result, ok := result_interface.(TestStruct)
func (*Client) Initialize ¶
Initialize is initialize.
ex) err := client.Initialize("localhost:27017", 10)
func (*Client) InsertMany ¶
InsertMany is insert a array type documents.
ex)
insertData := make([]any, 0) insertData = append(insertData, TestStruct{Value1: 1, Value2: "abc"}, TestStruct{Value1: 2, Value2: "def"}) err := client.InsertMany("test_database", "test_collection", insertData)
func (*Client) InsertOne ¶
InsertOne is insert a one document.
ex) err := client.InsertOne("test_database", "test_collection", TestStruct{})
func (*Client) UpdateMany ¶
UpdateMany is update the value corresponding to the filter argument with the values of the "update" argument.
ex) err := client.UpdateMany("test_database", "test_collection", bson.M{"value1": 1}, bson.D{{"$set", bson.D{{"value2", "update_value"}}}})