bulk

package
Version: v0.0.0-...-8cc84bd Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const BulkPacketSize = 16000000

BulkPacketSize maximum document size for MongoDB is 16793600 bytes. To avoid reaching that value, set max size to a bit less to avoid any overhead.

View Source
const BulkSizeMax = 1000

BulkSizeMax is the maximum number of bulk operations that can be handled before a flush to database is triggered.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bulk

type Bulk interface {
	// AddInsert handle up to max documents per add
	AddInsert(insert OpInsert) (*mgo.BulkResult, error)
	// AddUpdate handle up to max documents per add
	AddUpdate(update OpUpdate) (*mgo.BulkResult, error)

	AddUpsert(update OpUpdate) (*mgo.BulkResult, error)

	// AddUniqUpdate overrides updates on the same id as long as the bulk
	// isnt flushed.
	AddUniqUpdate(id string, update OpUpdate) (*mgo.BulkResult, error)

	// PerformInserts run the bulk operation
	PerformInserts() (*mgo.BulkResult, error)
	// PerformUpdates run the bulk operation
	PerformUpdates() (*mgo.BulkResult, error)

	// PerformUniqUpdates ...
	PerformUniqUpdates() (*mgo.BulkResult, error)
}

Bulk allows you to send documents to MongoDB by batches. See bulk.New() and bulk.NewSafe() for more details.

func New

func New(collection *mgo.Collection, max int) Bulk

New creates an thread-UNSAFE bulk struct and returns it under the Bulk interface. Insert operations are unordered while updates are ordered.

max is used to limit the number of documents you can queue in a bulk before it is flushed to the database.

If max > BulkSizeMax it's value is limited to BulkSizeMax.

func NewSafe

func NewSafe(unsafe Bulk) Bulk

NewSafe wrap the given unsafe Bulk to a thread safe bulk using sync.RWMutex.

type OpInsert

type OpInsert interface {
	// Data is the document to be inserted
	Data() interface{}
}

OpInsert handle creation of a bulk insert

func NewInsert

func NewInsert(data interface{}) OpInsert

NewInsert creates an insert operation.

type OpUpdate

type OpUpdate interface {
	// Selector is a mongo filter used to select documents to be updated.
	Selector() interface{}
	// Data is the query used to perform the update
	Data() interface{}
}

OpUpdate handle creation of a bulk update

func NewUpdate

func NewUpdate(selector interface{}, data interface{}) OpUpdate

NewUpdate creates an update operation.

selector is a MongoDB filter to match document(s) to be updated with the data parameter.

Jump to

Keyboard shortcuts

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