mongomove

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 13 Imported by: 0

README

mongomove

PkgGoDev

This tool imports your databases from one MongoDB server to another. I use this package when I need to import databases from MongoDB Atlas to my local machine for development.

Install

Binary
go install github.com/bounoable/mongomove/cmd/mongomove@latest
As a library
go get github.com/bounoable/mongomove

Import all databases

Import all databases from mongodb://127.0.0.1:27017 to mongodb://127.0.0.1:27018:

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018

Filter databases by prefix

Import all databases that have the my_ prefix from mongodb://127.0.0.1:27017 to mongodb://127.0.0.1:27018:

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -prefix my_

Skip confirmation

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -confirm

Insert documents in batches

Default batch size is 100. Following command inserts documents in batches of 500 documents:

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -b 500

Parallelize import

By default mongomove uses the number of CPUs to parallelize the import, so that 1 CPU is importing 1 database at a time. The following command imports 2 databases concurrently until all databases have been imported:

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -p 2

Disable index creation

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -indexes false

Verbose output

mongomove -source mongodb://127.0.0.1:27017 -target mongodb://127.0.0.1:27018 -v

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPrefix

func HasPrefix(prefix string) func(string) bool

HasPrefix returns a function that checks if a given string has the specified prefix. The returned function accepts a string and returns true if the input string starts with the specified prefix, otherwise false.

Types

type ImportOption

type ImportOption func(*importConfig)

ImportOption is a configuration function that modifies the importConfig struct, allowing users to customize the behavior of the Importer when importing data from one MongoDB instance to another. It provides options for filtering databases, ensuring indexes, dropping existing data, skipping confirmation prompts, and adjusting parallelism and batch sizes for performance tuning.

func BatchSize added in v0.2.2

func BatchSize(size int) ImportOption

BatchSize sets the size of the batches used when importing data from the source to the target database.

func Drop

func Drop(drop bool) ImportOption

Drop sets the drop option for the importConfig. If true, the target database will be dropped before importing data.

func EnsureIndexes added in v0.3.2

func EnsureIndexes(ensure bool) ImportOption

EnsureIndexes sets the ensureIndexes field in the importConfig struct to the provided boolean value. If set to true, the function ensures that indexes are created on the target database during the import process.

func Exclude added in v0.3.1

func Exclude(exprs ...*regexp.Regexp) ImportOption

func FilterDatabases

func FilterDatabases(filter ...func(string) bool) ImportOption

FilterDatabases returns an ImportOption that appends one or more filter functions to the importConfig's dbFilter list. These filter functions are used to determine which databases should be imported.

func Parallel added in v0.2.0

func Parallel(p int) ImportOption

Parallel sets the number of parallel import operations to be performed by the Importer. It takes an integer value as an input and returns an ImportOption function.

func PingTimeout

func PingTimeout(d time.Duration) ImportOption

PingTimeout sets the duration for the ping timeout when establishing a connection to the source and target MongoDB instances.

func SkipConfirm

func SkipConfirm(skip bool) ImportOption

SkipConfirm sets whether to skip the confirmation prompt during the import process. If set to true, it will bypass the confirmation and proceed with the import without user interaction.

func Verbose

func Verbose(v bool) ImportOption

Verbose sets the verbosity of the import process. If set to true, additional log messages will be printed during the import process.

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

Importer is a type that performs data import operations between two MongoDB instances, handling database filtering, index management, and parallel processing for efficient data transfers. It provides options to customize the import process, such as specifying filters for databases, ensuring indexes are created on the target instance, and configuring batch sizes and parallel processing.

func New

func New(source, target *mongo.Client) *Importer

New creates a new Importer instance with the specified source and target MongoDB clients. The source and target clients must not be nil; otherwise, it panics.

func (*Importer) Import

func (i *Importer) Import(ctx context.Context, opts ...ImportOption) error

Import imports the specified databases from the source MongoDB client to the target MongoDB client using the provided import options. It handles database filtering, dropping existing databases, ensuring indexes, and parallelizing import operations.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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