Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

database

v0.0.0-20230630043320-433fd72654f0
github.com/ioVN/database

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

7 matches

Top ↑

Functions

MongoConnect

func MongoConnect(uri, dbname string, timeout time.Duration) (*mongo.Database, error)

MongoConnect : create a new connection to mongodb

Example :

db, err := MongoConnect("mongodb://localhost:27017/testDB", "testDB", 30*time.Second)

if err != nil {
	log.Fatal(err)
}
if _, err := db.ListCollectionSpecifications(ctx, bson.M{}); err != nil {
	 log.Fatal(err)
}

MongoInit

func MongoInit(db *mongo.Database, collectionName string, index ...MongoIndex) *mongo.Collection

MongoInit : make collection with indexes

ParseMongoURI

func ParseMongoURI(uri string) (dbURI, dbname string)

Types

MongoIndex

type MongoIndex struct {
	Keys   interface{}
	Unique bool
}

MakeMongoIndex

func MakeMongoIndex(keys bson.D, unique bool) MongoIndex

MakeMongoIndex - make MongoIndex by keys

Dependency graph