|
|
@ -25,25 +25,15 @@ type (
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Deprecated. Use NewBatchInserter instead.
|
|
|
|
// NewBulkInserter returns a BulkInserter.
|
|
|
|
func NewBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
|
|
|
|
func NewBulkInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) {
|
|
|
|
return newBulkInserter(coll, interval...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewBatchInserter returns a BulkInserter.
|
|
|
|
|
|
|
|
func NewBatchInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) {
|
|
|
|
|
|
|
|
cloneColl, err := coll.Clone()
|
|
|
|
cloneColl, err := coll.Clone()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return newBulkInserter(cloneColl, interval...), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// newBulkInserter returns a BulkInserter.
|
|
|
|
|
|
|
|
func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
|
|
|
|
|
|
|
|
inserter := &dbInserter{
|
|
|
|
inserter := &dbInserter{
|
|
|
|
collection: coll,
|
|
|
|
collection: cloneColl,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
duration := flushInterval
|
|
|
|
duration := flushInterval
|
|
|
@ -54,7 +44,7 @@ func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkIns
|
|
|
|
return &BulkInserter{
|
|
|
|
return &BulkInserter{
|
|
|
|
executor: executors.NewPeriodicalExecutor(duration, inserter),
|
|
|
|
executor: executors.NewPeriodicalExecutor(duration, inserter),
|
|
|
|
inserter: inserter,
|
|
|
|
inserter: inserter,
|
|
|
|
}
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Flush flushes the inserter, writes all pending records.
|
|
|
|
// Flush flushes the inserter, writes all pending records.
|
|
|
|