gomongo

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: MIT Imports: 7 Imported by: 0

README

GoMongo

GoMongo is a wrapper for mongo-go-driver.

Documentation

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
}

func Open

func Open(
	ctx context.Context,
	addr string,
	appname string,
	names ...string,
) (*MongoDB, error)

Open create an instance to keep MongoDB info and connects to server. If names is specfied, the first one is database name, and others are collection names.

func (*MongoDB) Client added in v0.2.0

func (m *MongoDB) Client() *mongo.Client

Client returns the mongodb client.

func (*MongoDB) Close

func (m *MongoDB) Close() error

Close disconnects the connection to the server.

func (*MongoDB) Collection added in v0.7.0

func (m *MongoDB) Collection(name string) (*mongo.Collection, error)

Collection returns a specified collection.

func (*MongoDB) Collections

func (m *MongoDB) Collections() map[string]*mongo.Collection

Collections returns all collections.

func (*MongoDB) CollectionsAreExisting added in v0.6.0

func (m *MongoDB) CollectionsAreExisting() bool

CollectionAreExisting return a boolt to indicate if all collections are existing.

func (*MongoDB) Connect

func (m *MongoDB) Connect() error

Connect establish a connection to server.

func (*MongoDB) Context

func (m *MongoDB) Context() context.Context

Context returns the context.

func (*MongoDB) CreateIndex added in v0.8.0

func (m *MongoDB) CreateIndex(name, key string, order int) (string, error)

CreateIndex creates an index on collection name.

func (*MongoDB) Database

func (m *MongoDB) Database() (*mongo.Database, error)

Database returns the database.

func (*MongoDB) DatabaseIsExisting added in v0.6.0

func (m *MongoDB) DatabaseIsExisting() bool

DatabaseIsExisting return a bool to indicate if a database is existing.

func (*MongoDB) DeleteOne

func (m *MongoDB) DeleteOne(name string, filter interface{}) (int64, error)

DeleteOne executes a delete command to delete at most one document from the specified collection.

func (*MongoDB) EstimatedDocumentCount

func (m *MongoDB) EstimatedDocumentCount(name string) (int64, error)

EstimatedDocumentCount gets an estimated of the number of documents in the specified collection.

func (*MongoDB) Find

func (m *MongoDB) Find(
	name string,
	filter interface{},
	docs *[]map[string]interface{},
	opts ...*options.FindOptions,
) error

Find stores the matching documents from the specified collection in a list.

func (*MongoDB) FindOne

func (m *MongoDB) FindOne(
	name string,
	filter interface{},
	doc interface{},
) error

FindOne stores the matching document from the specified collection in an interface.

func (*MongoDB) InsertMany added in v0.9.0

func (m *MongoDB) InsertMany(name string, docs []interface{}) error

InsertMany executes an insert command to insert multiple documents into the specified collection.

func (*MongoDB) InsertOne

func (m *MongoDB) InsertOne(name string, doc interface{}) error

InsertOne executes an insert command to insert a single document into the specified collection.

func (*MongoDB) Ping

func (m *MongoDB) Ping() error

Ping sends a ping command to verify that the client can connect to the deployment.

func (*MongoDB) ReplaceOne

func (m *MongoDB) ReplaceOne(
	name string,
	filter interface{},
	doc interface{},
	upsert bool,
) (bool, error)

ReplaceOne executes an update command to replace at most one document in the specified collection. If upsert is true, a new document will be inserted if the filter does not match any documents in the collection.

func (*MongoDB) SetCollections

func (m *MongoDB) SetCollections(names ...string) error

SetCollections sets one or more collections.

func (*MongoDB) SetDatabase

func (m *MongoDB) SetDatabase(name string)

SetDatabase configures the database.

Jump to

Keyboard shortcuts

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