mongodb

package
v0.0.0-...-0871eb3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertDateTime

func ConvertDateTime()

ConvertDateTime is to convert datetime GMT MongoDB stores times in UTC by default

func GetObjectID

func GetObjectID(ID bson.ObjectId) string

GetObjectID is to get ObjectId as string

func LoadJSONFile

func LoadJSONFile(filePath string) ([]byte, error)

LoadJSONFile is to load JSON file

func New

func New(host, db, user, pass string, port uint16)

New is to create instance for singleton

Types

type MongoInfo

type MongoInfo struct {
	Session *mgo.Session
	Db      *mgo.Database
	C       *mgo.Collection
	// contains filtered or unexported fields
}

MongoInfo is for MongoDB instance

func GetMongo

func GetMongo() *MongoInfo

GetMongo is to get instance. singleton architecture

This is for singleton design pattern

func NewInstance

func NewInstance(host, db, user, pass string, port uint16) (*MongoInfo, error)

NewInstance makes a new instance

func (*MongoInfo) Close

func (mi *MongoInfo) Close()

Close is to close connection

func (*MongoInfo) DelAllDocs

func (mi *MongoInfo) DelAllDocs(colName string) (err error)

DelAllDocs is to delete all documents record from collection. Version3.x

func (*MongoInfo) DropCol

func (mi *MongoInfo) DropCol(colName string) (err error)

DropCol is to drop collection

func (*MongoInfo) DropDB

func (mi *MongoInfo) DropDB(dbName string) error

DropDB is to drop database

func (*MongoInfo) FindOne

func (mi *MongoInfo) FindOne(bd bson.M, data interface{}) error

FindOne is query to find one

func (*MongoInfo) GetCol

func (mi *MongoInfo) GetCol(colName string) *mgo.Collection

GetCol is to get and set collection

func (*MongoInfo) GetCount

func (mi *MongoInfo) GetCount() int

GetCount is to get count

func (*MongoInfo) GetDB

func (mi *MongoInfo) GetDB(dbName string) *mgo.Database

GetDB is reset session.DB object to mi.db

func (*MongoInfo) SetExpireOnCollection

func (mi *MongoInfo) SetExpireOnCollection(sessionExpire time.Duration) error

SetExpireOnCollection is to set expired date to collection

Jump to

Keyboard shortcuts

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