mongo

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MongoBatchSize = 2000
)

Functions

func AndQuery

func AndQuery(qs []bson.M) bson.M

func BsonM2Struct

func BsonM2Struct(m bson.M, s interface{}) (status bool)

m bson.M s SomeStruct BsonM2Struct(m, &s)

func CaseInsensitiveQuery

func CaseInsensitiveQuery(value interface{}) bson.M

func FuzzyQuery

func FuzzyQuery(value interface{}) bson.M

func InQuery

func InQuery(valueList interface{}) bson.M

func IsObjectIdHex

func IsObjectIdHex(s string) bool

func NExistQuery

func NExistQuery() bson.M

func NewObjectId

func NewObjectId() bson.ObjectId

NewObjectId returns a new unique ObjectId.

func NinQuery

func NinQuery(valueList interface{}) bson.M

func NotQuery

func NotQuery(value interface{}) bson.M

func OrQuery

func OrQuery(qs []bson.M) bson.M

func SafeToObjectId

func SafeToObjectId(s string) (bson.ObjectId, error)

func SafeToObjectIdOrEmpty

func SafeToObjectIdOrEmpty(s string) bson.ObjectId

func SetOperator

func SetOperator(value interface{}) bson.M

func SizeQuery

func SizeQuery(size int) bson.M

func ToObjectIdHex

func ToObjectIdHex(s string) bson.ObjectId

Types

type Auth

type Auth struct {
	Source    string
	Username  string
	Password  string
	Mechanism string
}

*

  • Database is the default database name used when the Session.DB method
  • is called with an empty name, and is also used during the initial
  • authentication if Source is unset. *
  • Username and Password inform the credentials for the initial authentication
  • done on the database defined by the Source field. See Session.Login. *

func (*Auth) UpdateDialInfo

func (auth *Auth) UpdateDialInfo(info *mgo.DialInfo)

type Client

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

func NewMongoClient

func NewMongoClient(addrs []string, db string, timeout time.Duration, auth *Auth) (client *Client, err error)

*

*
*  Addrs holds the addresses for the seed servers.
*
*  Database is the default database name used when the Session.DB method
*  is called with an empty name, and is also used during the initial
*  authentication if Source is unset.
*
*  Username and Password inform the credentials for the initial authentication
*  done on the database defined by the Source field. See Session.Login.
*
*  Timeout is the amount of time to wait for a server to respond when
*  first connecting and on follow up operations in the session. If
*  timeout is zero, the call may block forever waiting for a connection
*  to be established. Timeout does not affect logic in DialServer.

func (*Client) All

func (client *Client) All(coll string, query bson.M, selector bson.M, results interface{}) error

func (*Client) AllSorted

func (client *Client) AllSorted(coll string, query bson.M, sort []string, selector bson.M, results interface{}) error

func (*Client) BulkUpdate

func (client *Client) BulkUpdate(coll string, pairs []interface{}) (err error)

func (*Client) Close

func (client *Client) Close()

func (*Client) Count

func (client *Client) Count(coll string, query bson.M) (int, error)

func (*Client) Exists

func (client *Client) Exists(coll string, query bson.M) bool

func (*Client) Insert

func (client *Client) Insert(coll string, data interface{}) error

Insert inserts one or more documents in the respective collection. In case the session is in safe mode (see the SetSafe method) and an error happens while inserting the provided documents, the returned error will be of type *LastError.

func (*Client) Iter

func (client *Client) Iter(coll string, query bson.M, out chan bson.M) error

func (*Client) NewMongoAutoCommiter

func (client *Client) NewMongoAutoCommiter(coll string) *MongoAutoCommitBuilder

func (*Client) One

func (client *Client) One(coll string, query bson.M, result interface{}) error

func (*Client) Remove

func (client *Client) Remove(coll string, query bson.M) error

func (*Client) Search

func (client *Client) Search(coll string, query bson.M, sort []string, offset int, size int, results interface{}) error

func (*Client) Spawn

func (client *Client) Spawn() (sub *Client)

func (*Client) Update

func (client *Client) Update(coll string, query bson.M, update interface{}) error

func (*Client) UpdateAll

func (client *Client) UpdateAll(coll string, query bson.M, update interface{}) (err error)

func (*Client) Upsert

func (client *Client) Upsert(coll string, query bson.M, update interface{}) error

Upsert finds a single document matching the provided selector document and modifies it according to the update document. If no document matching the selector is found, the update document is applied to the selector document and the result is inserted in the collection. If the session is in safe mode (see SetSafe) details of the executed operation are returned in info, or an error of type *LastError when some problem is detected.

Relevant documentation:

http://www.mongodb.org/display/DOCS/Updating
http://www.mongodb.org/display/DOCS/Atomic+Operations

func (*Client) UseDB

func (client *Client) UseDB(db string) *Client

type MongoAutoCommitBuilder

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

*

*

func (*MongoAutoCommitBuilder) BulkActions

func (s *MongoAutoCommitBuilder) BulkActions(bulkActions int) *MongoAutoCommitBuilder

BulkActions specifies when to flush based on the number of actions currently added. Defaults to 1000 and can be set to -1 to be disabled.

func (*MongoAutoCommitBuilder) Collection

Collection defined the target coll

func (*MongoAutoCommitBuilder) FlushInterval

func (s *MongoAutoCommitBuilder) FlushInterval(interval time.Duration) *MongoAutoCommitBuilder

func (*MongoAutoCommitBuilder) Name

Name is an optional name to identify this bulk processor.

func (*MongoAutoCommitBuilder) Start

func (s *MongoAutoCommitBuilder) Start() (mac *MongoAutoCommitter, err error)

func (*MongoAutoCommitBuilder) Verbose

func (s *MongoAutoCommitBuilder) Verbose(verbose bool) *MongoAutoCommitBuilder

func (*MongoAutoCommitBuilder) Workers

Workers is the number of concurrent workers allowed to be executed. Defaults to 1 and must be greater or equal to 1.

type MongoAutoCommitter

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

func (*MongoAutoCommitter) Close

func (p *MongoAutoCommitter) Close() error

Close stops the bulk processor previously started with Do. If it is already stopped, this is a no-op and nil is returned.

By implementing Close, BulkProcessor implements the io.Closer interface.

func (*MongoAutoCommitter) Flush

func (p *MongoAutoCommitter) Flush() error

Flush manually asks all workers to commit their outstanding requests. It returns only when all workers acknowledge completion.

func (*MongoAutoCommitter) Insert

func (p *MongoAutoCommitter) Insert(doc interface{}) (e error)

Add adds a single request to commit by the BulkProcessorService.

The caller is responsible for setting the index and type on the request.

func (*MongoAutoCommitter) Start

func (p *MongoAutoCommitter) Start() error

func (*MongoAutoCommitter) Stop

func (p *MongoAutoCommitter) Stop() error

Stop is an alias for Close.

func (*MongoAutoCommitter) Update

func (p *MongoAutoCommitter) Update(pair []interface{}) (e error)

Add adds a single request to commit by the BulkProcessorService.

The caller is responsible for setting the index and type on the request.

func (*MongoAutoCommitter) Upsert

func (p *MongoAutoCommitter) Upsert(pair []interface{}) (e error)

Add adds a single request to commit by the BulkProcessorService.

The caller is responsible for setting the index and type on the request.

Jump to

Keyboard shortcuts

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