Documentation ¶
Overview ¶
Package mongoimport allows importing content from a JSON, CSV, or TSV into a MongoDB instance.
Index ¶
Constants ¶
const ( CSV = "csv" TSV = "tsv" JSON = "json" )
Input format types accepted by mongoimport.
Variables ¶
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") )
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.
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 ¶
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 `` /* 143-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" description:"comma-separated fields for the query part of the upsert"` // Sets write concern level for write operations. WriteConcern string `` /* 207-byte string literal not displayed */ }
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" 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" 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" 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 `long:"type" default:"json" default-mask:"-" description:"input format to import: json, csv, or tsv (defaults to 'json')"` }
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.
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.
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.