feat: add batch inserter (#2755)

This commit is contained in:
MarkJoyMa
2023-01-06 23:30:50 +08:00
committed by GitHub
parent fc9b3ffdc1
commit a5fcf24c04
2 changed files with 34 additions and 1 deletions

View File

@@ -25,8 +25,23 @@ type (
}
)
// NewBulkInserter returns a BulkInserter.
// Deprecated. Use NewBatchInserter instead.
func NewBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
return newBulkInserter(coll, interval...)
}
// NewBatchInserter returns a BulkInserter.
func NewBatchInserter(coll Collection, interval ...time.Duration) (*BulkInserter, error) {
cloneColl, err := coll.Clone()
if err != nil {
return nil, err
}
return newBulkInserter(cloneColl, interval...), nil
}
// newBulkInserter returns a BulkInserter.
func newBulkInserter(coll *mongo.Collection, interval ...time.Duration) *BulkInserter {
inserter := &dbInserter{
collection: coll,
}