mongodb

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 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 string, collectionName string, filter interface{}) 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 string, collectionName string, filter interface{}) 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 string, collectionName string, filter interface{}, dataForm interface{}) (interface{}, 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 string, collectionName string, filter interface{}, dataForm interface{}) (interface{}, 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 uint64) error

Initialize is initialize.

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

func (*Client) InsertMany

func (this *Client) InsertMany(databaseName string, collectionName string, documents []interface{}) error

InsertMany is insert a array type documents.

ex)

insertData := make([]interface{}, 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 string, collectionName string, document interface{}) error

InsertOne is insert a one document.

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

func (*Client) UpdateMany

func (this *Client) UpdateMany(databaseName string, collectionName string, filter interface{}, update interface{}) 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 string, collectionName string, filter interface{}, update interface{}) 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