mongodb

package
v0.0.0-...-af71eb0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Example
c, err := mongodb.Dial("localhost", 10)
if err != nil {
	fmt.Println(err)
	return
}
defer c.Close()

// session
s := c.Ref()
defer c.UnRef(s)
err = s.DB("test").C("counters").RemoveId("test")
if err != nil && err != mgo.ErrNotFound {
	fmt.Println(err)
	return
}

// auto increment
err = c.EnsureCounter("test", "counters", "test")
if err != nil {
	fmt.Println(err)
	return
}
for i := 0; i < 3; i++ {
	id, err := c.NextSeq("test", "counters", "test")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(id)
}

// index
c.EnsureUniqueIndex("test", "counters", []string{"key1"})
Output:

1
2
3

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DialContext

type DialContext struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func Dial

func Dial(url string, sessionNum int) (*DialContext, error)

goroutine safe

func DialWithTimeout

func DialWithTimeout(url string, sessionNum int, dialTimeout time.Duration, timeout time.Duration) (*DialContext, error)

goroutine safe

func (*DialContext) Close

func (c *DialContext) Close()

goroutine safe

func (*DialContext) EnsureCounter

func (c *DialContext) EnsureCounter(db string, collection string, id string) error

goroutine safe

func (*DialContext) EnsureIndex

func (c *DialContext) EnsureIndex(db string, collection string, key []string) error

goroutine safe

func (*DialContext) EnsureUniqueIndex

func (c *DialContext) EnsureUniqueIndex(db string, collection string, key []string) error

goroutine safe

func (*DialContext) NextSeq

func (c *DialContext) NextSeq(db string, collection string, id string) (int, error)

goroutine safe

func (*DialContext) Ref

func (c *DialContext) Ref() *Session

goroutine safe

func (*DialContext) UnRef

func (c *DialContext) UnRef(s *Session)

goroutine safe

type Session

type Session struct {
	*mgo.Session
	// contains filtered or unexported fields
}

session

type SessionHeap

type SessionHeap []*Session

session heap

func (SessionHeap) Len

func (h SessionHeap) Len() int

func (SessionHeap) Less

func (h SessionHeap) Less(i, j int) bool

func (*SessionHeap) Pop

func (h *SessionHeap) Pop() interface{}

func (*SessionHeap) Push

func (h *SessionHeap) Push(s interface{})

func (SessionHeap) Swap

func (h SessionHeap) Swap(i, j int)

Jump to

Keyboard shortcuts

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