gmongo

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Id2String

func Id2String(id interface{}) string

Types

type Cmp

type Cmp string
const (
	CmpLT  Cmp = "$lt"
	CmpLTE Cmp = "$lte"
	CmpGT  Cmp = "$gt"
	CmpGTE Cmp = "$gte"
)

type Coll

type Coll struct {
	// contains filtered or unexported fields
}

func (*Coll) CloneTo

func (c *Coll) CloneTo(to *Coll) (cloneCount int, err error)

TODO: test (again) required copy all data to new collection

func (*Coll) Count

func (c *Coll) Count(filter interface{}) (int64, error)

count by documents WARNING: this API is slow but correct if metadata is incorrect

func (*Coll) Exist

func (c *Coll) Exist() (bool, error)

func (*Coll) Find

func (c *Coll) Find(query interface{}) (*Cursor, error)

if DB / Coll doesn't exist, returns valid *Cursor and nil error, but cur.Next() == false

func (*Coll) FindCmp

func (c *Coll) FindCmp(path string, cmpopt Cmp, value bsonx.Val) (*Cursor, error)

example: FindCmp("_id", mongo.CmpGTE, bsonx.T(fromTime))

func (*Coll) FindEdge

func (c *Coll) FindEdge(limit int64, asc bool) (*Cursor, error)

asc, true ASC, false DESC

func (*Coll) FindId

func (c *Coll) FindId(id interface{}, decodeResult interface{}) (found bool, err error)

func (*Coll) IdExists

func (c *Coll) IdExists(id interface{}) (bool, error)

func (*Coll) Insert

func (c *Coll) Insert(doc interface{}) error

func (*Coll) InsertIfNotExists

func (c *Coll) InsertIfNotExists(selector interface{}, update interface{}) error

未测试! if not exists: insert

func (*Coll) InsertMany

func (c *Coll) InsertMany(docs ...interface{}) error

func (*Coll) Max

func (c *Coll) Max(itemPath string, typeSample interface{}) (interface{}, error)

func (*Coll) MaxFloat

func (c *Coll) MaxFloat(floatPath string) (float64, error)

func (*Coll) MaxInt64

func (c *Coll) MaxInt64(intPath string) (int64, error)

NOTE: if collection not exist, will returne [0, false, nil]

func (*Coll) MaxTime

func (c *Coll) MaxTime(intPath string) (time.Time, error)

NOTE: if collection not exist, will returne [0, false, nil]

func (*Coll) Min

func (c *Coll) Min(itemPath string, typeSample interface{}) (interface{}, error)

func (*Coll) MinFloat

func (c *Coll) MinFloat(floatPath string) (float64, error)

func (*Coll) MinInt64

func (c *Coll) MinInt64(intPath string) (int64, error)

NOTE: if collection not exist, will returne [0, false, nil]

func (*Coll) MinTime

func (c *Coll) MinTime(intPath string) (time.Time, error)

NOTE: if collection not exist, will returne [0, false, nil]

func (*Coll) Remove

func (c *Coll) Remove(selector interface{}) error

func (*Coll) RemoveAll

func (c *Coll) RemoveAll(selector interface{}) error

func (*Coll) RemoveCmp

func (c *Coll) RemoveCmp(path string, cmpopt Cmp, value bsonx.Val) (int64, error)

func (*Coll) RemoveCmpIntId

func (c *Coll) RemoveCmpIntId(id int64, cmpopt Cmp) error

func (*Coll) RemoveId

func (c *Coll) RemoveId(id interface{}) error

func (*Coll) RemoveObjectId

func (c *Coll) RemoveObjectId(id primitive.ObjectID) error

func (*Coll) RemovePartDocs

func (c *Coll) RemovePartDocs(selector interface{}, toRemove interface{}) error

未测试!

func (*Coll) RemoveStringId

func (c *Coll) RemoveStringId(stringId string) error

func (*Coll) Upsert

func (c *Coll) Upsert(selector interface{}, update interface{}) error

if not exists: insert, if exists: update

func (*Coll) UpsertEntireDoc

func (c *Coll) UpsertEntireDoc(id interface{}, doc interface{}) error

note: time.Time precision in MongoDB is Milliseconds, but in Go it is Nanoseconds, if time.Time used to be _id of document, please note the precision!

func (*Coll) UpsertFields

func (c *Coll) UpsertFields(id interface{}, doc interface{}) error

if not exists: insert, if exists: update

func (*Coll) VerifyContinuousInt64Id

func (c *Coll) VerifyContinuousInt64Id() (*grange.RangeFilter, error)

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func Dial

func Dial(uri string) (*Conn, error)

uri example: mongodb:192.168.7.11:34567

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CopyColl

func (mg *Conn) CopyColl(fromDb, fromColl, toDb, toColl string) (cloneCount int, err error)

copy all data to new collection

func (*Conn) DB

func (c *Conn) DB(DBName string) *Database

IMPORTANT Various indications in practical applications, this will create new socket connection between app and server. Need official document to prove this.

func (*Conn) DBExist

func (c *Conn) DBExist(dbName string) (bool, error)

func (*Conn) DBNames

func (c *Conn) DBNames() ([]string, error)

type ConnFromPool

type ConnFromPool struct {
	// contains filtered or unexported fields
}

func (*ConnFromPool) RawConn

func (ce *ConnFromPool) RawConn() *Conn

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

func (*Cursor) Decode

func (c *Cursor) Decode(result interface{}) error

Note: 存储的时间如果是UTC时区,Decode出来的会变成Local时区,需要仔细转换时区

func (*Cursor) DecodeBson

func (c *Cursor) DecodeBson() (bson.Raw, error)

TODO: test required, test at CloneTo()

func (*Cursor) DecodeId

func (c *Cursor) DecodeId(typeSample interface{}) (interface{}, error)

TODO: test required get Id of current document, use to recognize some special documents which has different structure compare with other documents

func (*Cursor) Next

func (c *Cursor) Next() bool

type Database

type Database struct {
	// contains filtered or unexported fields
}

func (*Database) C

func (d *Database) C(collName string) *Coll

func (*Database) CExists

func (d *Database) CExists(collName string) (bool, error)

func (*Database) CNames

func (d *Database) CNames() ([]string, error)

func (*Database) DeleteC

func (d *Database) DeleteC(collName string) error

func (*Database) Exist

func (d *Database) Exist() (bool, error)

func (*Database) RenameC

func (d *Database) RenameC(from, to string) error

func (*Database) Watch

func (d *Database) Watch() error

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func DialPool

func DialPool(mongodbUrl string, size int) (*Pool, error)

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) GetAvailable

func (p *Pool) GetAvailable() (*ConnFromPool, bool)

func (*Pool) Ping

func (p *Pool) Ping() error

func (*Pool) PutBack

func (p *Pool) PutBack(cex **ConnFromPool)

func (*Pool) WaitAvailable

func (p *Pool) WaitAvailable() *ConnFromPool

Jump to

Keyboard shortcuts

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