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 ¶
- type DialContext
- func (c *DialContext) Close()
- func (c *DialContext) EnsureCounter(db string, collection string, id string) error
- func (c *DialContext) EnsureIndex(db string, collection string, key []string) error
- func (c *DialContext) EnsureUniqueIndex(db string, collection string, key []string) error
- func (c *DialContext) NextSeq(db string, collection string, id string) (int, error)
- func (c *DialContext) Ref() *Session
- func (c *DialContext) UnRef(s *Session)
- type Session
- type SessionHeap
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialContext ¶
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
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)
Click to show internal directories.
Click to hide internal directories.