Documentation
¶
Overview ¶
Mongo Auto Committer is a simple tool to submit a batch of mongo request automatically It was based on Oliver's bulk_processor.go for Elastic see: https://git.io/fjK56
Index ¶
- Variables
- func AndQuery(qs []bson.M) bson.M
- func BsonM2Struct(m bson.M, s interface{}) (status bool)
- func FuzzyQuery(value interface{}) bson.M
- func InQuery(valueList interface{}) bson.M
- func IncOperator(valueList interface{}) bson.M
- func IsObjectIdHex(s string) bool
- func NExistQuery() bson.M
- func NewObjectId() bson.ObjectId
- func NinQuery(valueList interface{}) bson.M
- func NotQuery(value interface{}) bson.M
- func OrQuery(qs []bson.M) bson.M
- func SafeToObjectId(s string) (bson.ObjectId, error)
- func SafeToObjectIdOrEmpty(s string) bson.ObjectId
- func SetOperator(value interface{}) bson.M
- func SizeQuery(size int) bson.M
- func ToObjectIdHex(s string) bson.ObjectId
- func UpdateDialInfoFromAuth(info *mgo.DialInfo, auth *config.MongoAuth)
- type AutoCommitBuilder
- func (s *AutoCommitBuilder) BulkActions(bulkActions int) *AutoCommitBuilder
- func (s *AutoCommitBuilder) Collection(coll string) *AutoCommitBuilder
- func (s *AutoCommitBuilder) FlushInterval(interval time.Duration) *AutoCommitBuilder
- func (s *AutoCommitBuilder) Name(name string) *AutoCommitBuilder
- func (s *AutoCommitBuilder) Start() (mac *AutoCommitter, err error)
- func (s *AutoCommitBuilder) Verbose(verbose bool) *AutoCommitBuilder
- func (s *AutoCommitBuilder) Workers(num int) *AutoCommitBuilder
- type AutoCommitter
- func (p *AutoCommitter) Close() error
- func (p *AutoCommitter) Flush() error
- func (p *AutoCommitter) Insert(doc interface{}) (e error)
- func (p *AutoCommitter) Start() error
- func (p *AutoCommitter) Stop() error
- func (p *AutoCommitter) Update(pair []interface{}) (e error)
- func (p *AutoCommitter) Upsert(pair []interface{}) (e error)
- type Client
- func (client *Client) All(coll string, query bson.M, selector bson.M, results interface{}) error
- func (client *Client) AllSorted(coll string, query bson.M, sort []string, selector bson.M, results interface{}) error
- func (client *Client) BulkUpdate(coll string, pairs []interface{}) (err error)
- func (client *Client) Close()
- func (client *Client) Count(coll string, query bson.M) (int, error)
- func (client *Client) EnsureIndexKey(coll string, key ...string) (err error)
- func (client *Client) Exists(coll string, query bson.M) bool
- func (client *Client) Insert(coll string, data interface{}) error
- func (client *Client) Iter(coll string, query bson.M, out chan bson.M) error
- func (client *Client) IterBatch(coll string, query bson.M, selector bson.M, batchSize int, ...) (err error)
- func (client *Client) IterSelect(coll string, query bson.M, selector bson.M, out chan bson.M) error
- func (client *Client) IterSync(coll string, query bson.M, selector bson.M, f func(bson.M) error) error
- func (client *Client) NewAutoCommitBuilder(coll string) *AutoCommitBuilder
- func (client *Client) One(coll string, query bson.M, result interface{}) error
- func (client *Client) Ping() error
- func (client *Client) Remove(coll string, query bson.M) error
- func (client *Client) Root() (sub *Client)
- func (client *Client) Search(coll string, query bson.M, sort []string, offset int, size int, ...) error
- func (client *Client) Spawn() (sub *Client)
- func (client *Client) Update(coll string, query bson.M, update interface{}) error
- func (client *Client) UpdateAll(coll string, query bson.M, update interface{}) (err error)
- func (client *Client) Upsert(coll string, query bson.M, update interface{}) error
- func (client *Client) UseDB(db string) *Client
Constants ¶
This section is empty.
Variables ¶
var (
MongoBatchSize = 2000
)
Functions ¶
func BsonM2Struct ¶
m bson.M s SomeStruct BsonM2Struct(m, &s)
func FuzzyQuery ¶
func IncOperator ¶
func IsObjectIdHex ¶
func NExistQuery ¶
func SafeToObjectIdOrEmpty ¶
func SetOperator ¶
func ToObjectIdHex ¶
Types ¶
type AutoCommitBuilder ¶
type AutoCommitBuilder struct {
// contains filtered or unexported fields
}
*
*
func (*AutoCommitBuilder) BulkActions ¶
func (s *AutoCommitBuilder) BulkActions(bulkActions int) *AutoCommitBuilder
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 (*AutoCommitBuilder) Collection ¶
func (s *AutoCommitBuilder) Collection(coll string) *AutoCommitBuilder
Collection defined the target coll
func (*AutoCommitBuilder) FlushInterval ¶
func (s *AutoCommitBuilder) FlushInterval(interval time.Duration) *AutoCommitBuilder
func (*AutoCommitBuilder) Name ¶
func (s *AutoCommitBuilder) Name(name string) *AutoCommitBuilder
Name is an optional name to identify this bulk processor.
func (*AutoCommitBuilder) Start ¶
func (s *AutoCommitBuilder) Start() (mac *AutoCommitter, err error)
func (*AutoCommitBuilder) Verbose ¶
func (s *AutoCommitBuilder) Verbose(verbose bool) *AutoCommitBuilder
func (*AutoCommitBuilder) Workers ¶
func (s *AutoCommitBuilder) Workers(num int) *AutoCommitBuilder
Workers is the number of concurrent workers allowed to be executed. Defaults to 1 and must be greater or equal to 1.
type AutoCommitter ¶
type AutoCommitter struct {
// contains filtered or unexported fields
}
func (*AutoCommitter) Close ¶
func (p *AutoCommitter) 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 (*AutoCommitter) Flush ¶
func (p *AutoCommitter) Flush() error
Flush manually asks all workers to commit their outstanding requests. It returns only when all workers acknowledge completion.
func (*AutoCommitter) Insert ¶
func (p *AutoCommitter) 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 (*AutoCommitter) Start ¶
func (p *AutoCommitter) Start() error
func (*AutoCommitter) Update ¶
func (p *AutoCommitter) 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 (*AutoCommitter) Upsert ¶
func (p *AutoCommitter) 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.
type Client ¶
type Client struct { Session *mgo.Session Db string Config config.MongoConfig // contains filtered or unexported fields }
func NewMongoClient ¶
func NewMongoClient(cfg config.MongoConfig) (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) BulkUpdate ¶
func (*Client) EnsureIndexKey ¶
func (*Client) Insert ¶
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) IterSelect ¶
func (*Client) NewAutoCommitBuilder ¶
func (client *Client) NewAutoCommitBuilder(coll string) *AutoCommitBuilder
func (*Client) Upsert ¶
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