common

package module
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 8 Imported by: 1

README

Golang Mongo Common

GitHub repo size GitHub Repo stars GitHub issues

Provide some Helpers functions for MongoDB use with Golang.

⚠️ License

Copyright (c) 2019-present Eduardo Hitek. Golang Mongo Common is free and open-source software licensed under the MIT License.

Documentation

Index

Constants

View Source
const ConnectTimeout = 10 * time.Second
View Source
const MaxConnIdleTime = 15 * time.Second
View Source
const ServerSelectionTimeout = 10 * time.Second

Variables

This section is empty.

Functions

func CreateIndex added in v1.7.0

func CreateIndex(client *mongo.Client, dbName string, collectionName string, field string, unique bool) error

Create an index with the provide name and condition

func DeleteManyByFilter added in v1.5.0

func DeleteManyByFilter(client *mongo.Client, dbName string, collectionName string,
	filter bson.M) (*mongo.DeleteResult, error)

Deletes one or many document by the informed filter

func DeleteOneByFilter added in v1.5.0

func DeleteOneByFilter(client *mongo.Client, dbName string, collectionName string,
	filter bson.M) (*mongo.DeleteResult, error)

Deletes one document by the informed filter

func DeleteOneByID added in v1.5.0

func DeleteOneByID(client *mongo.Client, dbName string, collectionName string,
	insertedID interface{}) (*mongo.DeleteResult, error)

Deletes a document by the informed ID

func FindAll added in v1.5.0

func FindAll(client *mongo.Client, dbName string, collectionName string, model interface{},
	filter bson.M) (interface{}, error)

Find one or more documents by the provided filter

func FindOne added in v1.5.0

func FindOne(client *mongo.Client, dbName string, collectionName string, model interface{},
	filter bson.M, findOption *options.FindOneOptions) (interface{}, error)

Find one document by the provided filter

func InsertMany added in v1.5.0

func InsertMany(client *mongo.Client, dbName string, collectionName string,
	models []interface{}) (*mongo.InsertManyResult, error)

Insert many documents

func InsertOne added in v1.5.0

func InsertOne(client *mongo.Client, dbName string, collectionName string,
	model interface{}) (*mongo.InsertOneResult, error)

Insert one document

func ReturnAuthenticatedClient added in v1.5.0

func ReturnAuthenticatedClient(url string, authDB string, user string, password string,
	appName string, createMonitor bool) (*mongo.Client, error)

Returns an authenticated mongodb client.

func ReturnAuthenticatedClientMongoAtlas added in v1.5.0

func ReturnAuthenticatedClientMongoAtlas(url string, user string, password string, db string,
	appName string, createMonitor bool) (*mongo.Client, error)

Return an autheticated mongodb client for Mongo Atlas

func ReturnClient added in v1.5.0

func ReturnClient(url string, appName string, createMonitor bool) (*mongo.Client, error)

Returns a non-authenticated mongodb client.

func Total

func Total(client *mongo.Client, dbName string, collectionName string, filter bson.M) (int64, error)

Returns the total number of documents in one collection

func UpdateByID added in v1.5.0

func UpdateByID(client *mongo.Client, dbName string, collectionName string, insertedID interface{},
	updatedField interface{}) (*mongo.UpdateResult, error)

Update a document by the provided ID

func UpdateManyByFilter added in v1.5.0

func UpdateManyByFilter(client *mongo.Client, dbName string, collectionName string, filter bson.M,
	updatedField interface{}) (*mongo.UpdateResult, error)

Update one or more documents by the provided filter

func UpdateOneByFilter added in v1.5.0

func UpdateOneByFilter(client *mongo.Client, dbName string, collectionName string, filter bson.M,
	updatedField interface{}) (*mongo.UpdateResult, error)

Update one document by the provided filter

Types

This section is empty.

Jump to

Keyboard shortcuts

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