mongodb

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mongodb provides mongodb interface.

used "go.mongodb.org/mongo-driver/mongo".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mongodb

type Mongodb struct {
	// contains filtered or unexported fields
}

Mongodb is object that provides mongodb interface.

func (*Mongodb) DeleteMany

func (mongodb *Mongodb) DeleteMany(databaseName string, collectionName string, filter interface{}) error

DeleteMany is delete the values corresponding to the filter argument.

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

func (*Mongodb) DeleteOne

func (mongodb *Mongodb) DeleteOne(databaseName string, collectionName string, filter interface{}) error

DeleteOne is delete one value corresponding to the filter argument.

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

func (*Mongodb) Finalize

func (mongodb *Mongodb) Finalize() error

Finalize is finalize.

ex) err := mongodb.Finalize()

func (*Mongodb) Find

func (mongodb *Mongodb) 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 := mongodb.Find("test_database", "test_collection", bson.M{}, TestStruct{})

results, ok := results_interface.([]TestStruct)

func (*Mongodb) FindOne

func (mongodb *Mongodb) 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 := mongodb.FindOne("test_database", "test_collection", bson.M{"value1": 1}, TestStruct{})

 result, ok := result_interface.(TestStruct)

func (*Mongodb) Initialize

func (mongodb *Mongodb) Initialize(address string, timeout uint64) error

Initialize is initialize.

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

func (*Mongodb) InsertMany

func (mongodb *Mongodb) 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 := mongodb.InsertMany("test_database", "test_collection", insertData)

func (*Mongodb) InsertOne

func (mongodb *Mongodb) InsertOne(databaseName string, collectionName string, document interface{}) error

InsertOne is insert a one document.

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

func (*Mongodb) UpdateMany

func (mongodb *Mongodb) 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 := mongodb.UpdateMany("test_database", "test_collection", bson.M{"value1": 1}, bson.D{{"$set", bson.D{{"value2", "update_value"}}}})

func (*Mongodb) UpdateOne

func (mongodb *Mongodb) 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 := mongodb.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