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

spawngo

v2.0.0

Published

Spawn a child process for mongoimport/export

Downloads

45

Readme

spawngo

A wrapper to spawn mongoimport/export processes

usage

const Spawngo = require('spawngo')

// create a new instance
let spawngo = new Spawngo({
  user: 'foo',
  pw: 'bar',
  'collection': 'bang'
})
// call #import() function and pass a file to import into mongoDb
// this will return a child process object
let childProcess = spawngo.import('my.json')

// handle events as needed
childProcess.stdout.on('data', function (data) {
  // block to handle stdout
})

childProcess.stderr.on('data', function (data) {
  // block to handle stderr
})

childProcess.on('close', function (data) {
  // block to handle close
})

Note that mongoDb sends ALL status updates to stderr, so to better determine if your process was successful, you should ensure the status code from theclose event returned a 0, and not rely on stderr.

Exporting is nearly identical to the above, but instead of import(), you would call export() to export the collection as defined when spawngo was instantiated, or updated using .set()

let childProcess = spawngo.export()

If you wish to export a different collection, but not alter the internal configurated collection, you can pass a string of the target collection,:

let childProcess = spawngo.export('collectionName')

api

Constructor(options) options (Object): Configuration object. Allowed properties are as follows (displayed with default values)

  • host: 'localhost'
  • user: ''
  • pwd: ''
  • db: ''
  • collection: ''
  • jsonArray: true
  • upsertFields: undefined
  • cpus: [default is number of machine's cpu cores]
  • drop: false

Instead of passing options to constructor, you can also apply your settings by using the .set() function.

If no user and password are set, then the call to mongoimport will not use authentication.

import(fileName)

fileName (String): Path of the json/csv/tsv file to import

returns: ChildProcess of the spawned query.

export(collection)

collection (String [optional]): Name of the collection to export. The exported json file will be named after the collection (i.e collectionName.json).

The string aurgument is optional. Not passing a string will use the collect as defined internally either via the constructor settings, or from using .set().

Note that passsing a collection string in this manner will NOT alter the internal configuration.

returns: ChildProcess of the spawned query.

set(optsObj or key, value)

optsObj (Object): Configuration object. See Constructor above to see all available options.

key (String), value (String): to update a single congiguration property, you may pass a key/value pair of strings as an argument: spawngo.set('collection', 'myThings').

returns: The spawngo instance.