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

mongonaut

v3.0.0

Published

NodeJS wrapper for mongoimport

Downloads

40

Readme

Mongonaut

NodeJS module that totally Promises to import your JSON, CSV or TSV files to MongoDB.

Usage

let mongonaut = new Mongonaut({
  'user': 'tomservo',
  'pwd': 'sol',
  'db': 'experiments',
  'collection': 'movies'
});

// pass a path to data file
mongonaut.import('./data.json')
  .then(function (response) {
    // code to fire on Promise resolve
  });

// change config to point to new collection
// then batch import multiple files.
mongonaut.set('collection', 'inventions');
  .import(['./data2.json', './some/other/data.json', './third.json'])
  .then(function (response) {
      // code to fire on Promise resolve
  });

// export "inventions" collection to a json file
mongonaut.export()
  .then(function (returnedCollections){
    // code to execute on Promise resolve
  });

Constructor(config)

config: object to apply configuration data. Available keys are host, user, pwd, db, collection which are used to authenticate with MongoDB, as well as options jsonArray - set as false if you want to use MongoDB's JSON format. (by default, Mongonaut will expect valid JSON files), and upsertFields if you need to specify fields

If authentication is not desired, then simply omit setting both user and pwd, or in the case of changing settings from using authentication to omitting authtentication, set both user and pwd to empty strings.

returns: Mongonaut instance.

.set([key, val] OR [config])

key: desired config key to set.

val: desired value of mongonaut.config[key]

config object to apply configuration data. Available keys are host, user, pwd, db, and collection which are used to authenticate with MongoDB.

If you intend to use MongoDB's default JSON formatting, then set jsonArray to false.

You can set upsertFields if you intend to specify specific fields for your query. Unless set by a user, Mongonaut ignores this setting.

Remember, both user and pwd must both either be set (for authentication), or set as the default/empty strings (for no authentication). Setting only one or the other will result in an error when you call .import().

note trying to set a key other than host, user, pwd, db or collection will result in an error.

returns: mongonaut

.import(targetfile)

targetFile: The file (.json, .csv, or .tsv) containing the data you wish to import to MongoDB.

returns: Promise

Resolving callback will be passed an object with two properties: code and out. The exit code from the import/export process will be the value of code, and out will contain general output. Note that mongomimport natively sends status info to stderr rather than stdout, so rather than be confusing, this output is attached to the out property of the object passed to the resolving function.

.export(collectionString)

collectionString: Name of a collection within the database set by the db property of a mongonaut instance.

Note that an argument for .export() is optional, and will default to the collection set within the instnace's configured collection property.

returns: Promise

Resolving callback will be passed an object similar as done in .import() which contains properties code (the exit code) and out data sent to stderr.

Breaking in v3

Previously, mongonaut took an array of files/collections. This has been removed in favor of only passing a single file/collection. It should be trivial to write one's own iterator over an array of files to replicate previous behavior if desired.

Object passed to resolving promises have different properties (out and code rather than file, stderr, and stdout). This is largely due to the fact that mongoimport does not send status info to stdout.

Run Tests

In a terminal:

npm install
npm test