Documentation ¶
Index ¶
Constants ¶
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.
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.
type OpInsert ¶
type OpInsert interface {
// Data is the document to be inserted
Data() interface{}
}
OpInsert handle creation of a bulk insert