mongoimport

package
v0.0.0-...-099f62a Latest Latest
Warning

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

Go to latest
Published: May 3, 2016 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package mongoimport allows importing content from a JSON, CSV, or TSV into a MongoDB instance.

Index

Constants

View Source
const (
	CSV  = "csv"
	TSV  = "tsv"
	JSON = "json"
)

Input format types accepted by mongoimport.

Variables

View Source
var (
	// ErrNoOpeningBracket means that the input source did not contain any
	// opening brace - returned only if --jsonArray is passed in.
	ErrNoOpeningBracket = errors.New("bad JSON array format - found no " +
		"opening bracket '[' in input source")

	// ErrNoClosingBracket means that the input source did not contain any
	// closing brace - returned only if --jsonArray is passed in.
	ErrNoClosingBracket = errors.New("bad JSON array format - found no " +
		"closing bracket ']' in input source")
)
View Source
var Usage = `` /* 203-byte string literal not displayed */

Functions

This section is empty.

Types

type CSVConverter

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

CSVConverter implements the Converter interface for CSV input.

func (CSVConverter) Convert

func (c CSVConverter) Convert() (bson.D, error)

Convert implements the Converter interface for CSV input. It converts a CSVConverter struct to a BSON document.

type CSVInputReader

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

CSVInputReader implements the InputReader interface for CSV input types.

func NewCSVInputReader

func NewCSVInputReader(fields []string, in io.Reader, numDecoders int) *CSVInputReader

NewCSVInputReader returns a CSVInputReader configured to read data from the given io.Reader, extracting only the specified fields using exactly "numDecoders" goroutines.

func (*CSVInputReader) ReadAndValidateHeader

func (r *CSVInputReader) ReadAndValidateHeader() (err error)

ReadAndValidateHeader reads the header from the underlying reader and validates the header fields. It sets err if the read/validation fails.

func (*CSVInputReader) StreamDocument

func (r *CSVInputReader) StreamDocument(ordered bool, readDocs chan bson.D) (retErr error)

StreamDocument takes a boolean indicating if the documents should be streamed in read order and a channel on which to stream the documents processed from the underlying reader. Returns a non-nil error if streaming fails.

type Converter

type Converter interface {
	Convert() (document bson.D, err error)
}

Converter is an interface that adds the basic Convert method which returns a valid BSON document that has been converted by the underlying implementation. If conversion fails, err will be set.

type IngestOptions

type IngestOptions struct {
	// Drops target collection before importing.
	Drop bool `long:"drop" description:"drop collection before inserting documents"`

	// Ignores fields with empty values in CSV and TSV imports.
	IgnoreBlanks bool `long:"ignoreBlanks" description:"ignore fields with empty values in CSV and TSV"`

	// Indicates that documents will be inserted in the order of their appearance in the input source.
	MaintainInsertionOrder bool `long:"maintainInsertionOrder" description:"insert documents in the order of their appearance in the input source"`

	// Sets the number of insertion routines to use
	NumInsertionWorkers int `` /* 165-byte string literal not displayed */

	// Forces mongoimport to halt the import operation at the first insert or upsert error.
	StopOnError bool `long:"stopOnError" description:"stop importing at first insert/upsert error"`

	// Modifies the import process to update existing objects in the database if they match --upsertFields.
	Upsert bool `long:"upsert" description:"insert or update objects that already exist"`

	// Specifies a list of fields for the query portion of the upsert; defaults to _id field.
	UpsertFields string `long:"upsertFields" value-name:"<field>[,<field>]*" description:"comma-separated fields for the query part of the upsert"`

	// Sets write concern level for write operations.
	WriteConcern string `` /* 246-byte string literal not displayed */

	// Indicates that the server should bypass document validation on import.
	BypassDocumentValidation bool `long:"bypassDocumentValidation" description:"bypass document validation"`
}

IngestOptions defines the set of options for storing data.

func (*IngestOptions) Name

func (_ *IngestOptions) Name() string

Name returns a description of the IngestOptions struct.

type InputOptions

type InputOptions struct {
	// Fields is an option to directly specify comma-separated fields to import to CSV.
	Fields *string `long:"fields" value-name:"<field>[,<field>]*" short:"f" description:"comma separated list of field names, e.g. -f name,age"`

	// FieldFile is a filename that refers to a list of fields to import, 1 per line.
	FieldFile *string `long:"fieldFile" value-name:"<filename>" description:"file with field names - 1 per line"`

	// Specifies the location and name of a file containing the data to import.
	File string `long:"file" value-name:"<filename>" description:"file to import from; if not specified, stdin is used"`

	// Treats the input source's first line as field list (csv and tsv only).
	HeaderLine bool `long:"headerline" description:"use first line in input source as the field list (CSV and TSV only)"`

	// Indicates that the underlying input source contains a single JSON array with the documents to import.
	JSONArray bool `long:"jsonArray" description:"treat input source as a JSON array"`

	// Specifies the file type to import. The default format is JSON, but it’s possible to import CSV and TSV files.
	Type string `` /* 140-byte string literal not displayed */
}

InputOptions defines the set of options for reading input data.

func (*InputOptions) Name

func (_ *InputOptions) Name() string

Name returns a description of the InputOptions struct.

type InputReader

type InputReader interface {
	// StreamDocument takes a boolean indicating if the documents should be streamed
	// in read order and a channel on which to stream the documents processed from
	// the underlying reader.  Returns a non-nil error if encountered.
	StreamDocument(ordered bool, read chan bson.D) error

	// ReadAndValidateHeader reads the header line from the InputReader and returns
	// a non-nil error if the fields from the header line are invalid; returns
	// nil otherwise. No-op for JSON input readers.
	ReadAndValidateHeader() error
	// contains filtered or unexported methods
}

type JSONConverter

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

JSONConverter implements the Converter interface for JSON input.

func (JSONConverter) Convert

func (c JSONConverter) Convert() (bson.D, error)

Convert implements the Converter interface for JSON input. It converts a JSONConverter struct to a BSON document.

type JSONInputReader

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

JSONInputReader is an implementation of InputReader that reads documents in JSON format.

func NewJSONInputReader

func NewJSONInputReader(isArray bool, in io.Reader, numDecoders int) *JSONInputReader

NewJSONInputReader creates a new JSONInputReader in array mode if specified, configured to read data to the given io.Reader.

func (*JSONInputReader) ReadAndValidateHeader

func (r *JSONInputReader) ReadAndValidateHeader() error

ReadAndValidateHeader is a no-op for JSON imports; always returns nil.

func (*JSONInputReader) StreamDocument

func (r *JSONInputReader) StreamDocument(ordered bool, readChan chan bson.D) (retErr error)

StreamDocument takes a boolean indicating if the documents should be streamed in read order and a channel on which to stream the documents processed from the underlying reader. Returns a non-nil error if encountered

type MongoImport

type MongoImport struct {
	// generic mongo tool options
	ToolOptions *options.ToolOptions

	// InputOptions defines options used to read data to be ingested
	InputOptions *InputOptions

	// IngestOptions defines options used to ingest data into MongoDB
	IngestOptions *IngestOptions

	// SessionProvider is used for connecting to the database
	SessionProvider *db.SessionProvider

	// the tomb is used to synchronize ingestion goroutines and causes
	// other sibling goroutines to terminate immediately if one errors out
	tomb.Tomb
	// contains filtered or unexported fields
}

MongoImport is a container for the user-specified options and internal state used for running mongoimport.

func (*MongoImport) ImportDocuments

func (imp *MongoImport) ImportDocuments() (uint64, error)

ImportDocuments is used to write input data to the database. It returns the number of documents successfully imported to the appropriate namespace and any error encountered in doing this

func (*MongoImport) ValidateSettings

func (imp *MongoImport) ValidateSettings(args []string) error

ValidateSettings ensures that the tool specific options supplied for MongoImport are valid.

type TSVConverter

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

TSVConverter implements the Converter interface for TSV input.

func (TSVConverter) Convert

func (c TSVConverter) Convert() (bson.D, error)

Convert implements the Converter interface for TSV input. It converts a TSVConverter struct to a BSON document.

type TSVInputReader

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

TSVInputReader is a struct that implements the InputReader interface for a TSV input source.

func NewTSVInputReader

func NewTSVInputReader(fields []string, in io.Reader, numDecoders int) *TSVInputReader

NewTSVInputReader returns a TSVInputReader configured to read input from the given io.Reader, extracting the specified fields only.

func (*TSVInputReader) ReadAndValidateHeader

func (r *TSVInputReader) ReadAndValidateHeader() (err error)

ReadAndValidateHeader reads the header from the underlying reader and validates the header fields. It sets err if the read/validation fails.

func (*TSVInputReader) StreamDocument

func (r *TSVInputReader) StreamDocument(ordered bool, readDocs chan bson.D) (retErr error)

StreamDocument takes a boolean indicating if the documents should be streamed in read order and a channel on which to stream the documents processed from the underlying reader. Returns a non-nil error if streaming fails.

Directories

Path Synopsis
Package csv reads and writes comma-separated values (CSV) files.
Package csv reads and writes comma-separated values (CSV) files.
Main package for the mongoimport tool.
Main package for the mongoimport tool.

Jump to

Keyboard shortcuts

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