npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongopack

v1.0.2

Published

Simple backup and restore tool pack for mongodb

Downloads

7

Readme

Description

Toolbox to for mongodb backup and restore. Makes import and export to and from file smooth. Supports imports from json|tsv|csv and export to csv|json.

Export API:

var mongoexport = require('mongopack').mongoexport;
var database = "company",
		collection = "awesome",
		destination = "cmp/backup",
		options = {
		type: "json", // default is csv
		pretty: true, // gives a pretty formatted json in output file
		field: ['_id', 'name', 'email', 'address', 'milestone'],
  };		
// perform export
mongoexport(database, collection, destination, options, function(err) {
	if (err) throw new Error();
  // yaay! export done!
	console.log("export completed, check output to verify");
})

Import API:

var mongoimport = require('mongopack').mongoimport;
var database = "company",
		collection = "awesome",
		file = "cmp/backup";
// perform import
mongoimport(database, collection, file, options, function(err, querydb) {
	if (err) throw new Error();
  querydb(); // just to verify import is done!
	console.log("import completed and verified");
})

Controlling import or export behaviour

  • --ssl --if the mongod process has TLS/SSL support enabled
    • --sslCAFile -- the file name of the .pem file using relative or absolute paths
    • --sslPEMKEYFile -- the .pem file that containes both the TLS/SSL certificate and key
    • --sslPEMKeyPassword -- the password
    • --sslCRLFile -- the filename
    • --sslAllowInvalidCertificates bypass the validataion checks for server certificates and allows the use of invalid certificates (mongodb logs a warning for this)
    • --sslFIPSMode directs the mongoexport to use FIPSMode of the installed OpenSSL library
    • --username to be used when operating on an authenticated in conjunction with --password
    • --password to be used in conjection with --username above
    • --authenticatedDatabase when not used mongodb assumes that the db specified to export holds the user's credentials
    • --authenticationMechanism Default:SCRAM-SHA-1, others supported are PLAIN and MONGODB-X509 authentication mechanism

Controlling export behaviour peculiar to data export

The following parameters are mandatory for mongoexport(params) as shown in the documentation

  • --host
  • --port
  • --fields--ipv6 --- always enable since 3.0
  • --db , -d
  • --collection , -c
  • --fields <field1[,field2]>, -f<field1[,field2]>
  • --fieldFile to be used when the fieldnamese are large and placed in a seperate file
  • --query , -q to be used in querying the data to be exported
  • --type specify the data type (eg. for csv -> --type=csv) -- default is json when it is a csv file,--fields or --fieldFile must be provided
  • --out , -o
  • --jsonArray this command tells mongoexport to export the entire data as an array of JSON files
  • --pretty to export the data in a pretty-printed format JSON
  • --slaveOk, -k (depracted in 3.2) use if version is before 3.2 to (see --readPreference)
  • --readPreference (--slaveOk, -k is depracated in 3.2), cannot specify both in a command it sets the read preference to the nearest when using a replica set, enabling mongoexport to read from the secondary replica set members

Controlling import behaviour peculiar to data import

The following parameters are mandatory for mongoimport(params) as shown in the documentation

  • --ignoreBlanks ignores empty fields in csv and tsv exports. if not specified mongoimport creates fields without values in imported documents
  • --drop tells mongoimport to drop the collection before operating on it.
  • --headerline tells mongoimport to use the first line in the input file as the field names
  • --fields To use if the input file does not contain the fields to be used as headers
  • --fieldFile to be used when the fieldnames are large and placed in a seperate file (to be placed one per line)
  • --upsert Modifies the import process to update existing objects in teh db if they match an imported object, while inserting other objects
  • --upsertFields <field1[,field2]>Specifies the list of fields for the query portion of the upsert (Since mongodb 3.0 upsertFields now implies upsert, so you may choose to use --upsertFields rather than --upsert)
  • --bypassDocumentValidation as name suggests, no document validation is done during the operation (new in 3.2.1)