mongodb

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mongodb provides MongoDB client implementations.

Index

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

func (this *Client) DeleteMany(databaseName, collectionName string, filter any) error

DeleteMany is delete the values corresponding to the filter argument.

ex) err := client.DeleteMany("test_database", "test_collection", bson.M{})

func (*Client) DeleteOne

func (this *Client) DeleteOne(databaseName, collectionName string, filter any) error

DeleteOne is delete one value corresponding to the filter argument.

ex) err := client.DeleteOne("test_database", "test_collection", bson.M{"value1": 1})

func (*Client) Finalize

func (this *Client) Finalize() error

Finalize is finalize.

ex) err := client.Finalize()

func (*Client) Find

func (this *Client) Find(databaseName, collectionName string, filter, dataForm any) (any, error)

"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

func (this *Client) Initialize(address string, timeout time.Duration) error

Initialize is initialize.

ex) err := client.Initialize("localhost:27017", 10)

func (*Client) InsertMany

func (this *Client) InsertMany(databaseName, collectionName string, documents []any) error

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

func (this *Client) InsertOne(databaseName, collectionName string, document any) error

InsertOne is insert a one document.

ex) err := client.InsertOne("test_database", "test_collection", TestStruct{})

func (*Client) UpdateMany

func (this *Client) UpdateMany(databaseName, collectionName string, filter, update any) error

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"}}}})

func (*Client) UpdateOne

func (this *Client) UpdateOne(databaseName, collectionName string, filter, update any) error

UpdateOne is update the one value corresponding to the filter argument with the value of the "update" argument.

ex) err := client.UpdateOne("test_database", "test_collection", bson.M{"value1": 1}, bson.D{{"$set", bson.D{{"value2", "update_value"}}}})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL