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

variety-cli

v0.5.0

Published

Node.js wrapper for Variety - MongoDB Schema Analyser

Downloads

58

Readme

variety-cli

Command line interface for the Variety Schema Analyser.

Build Status Coverage Status Build status Dependencies Status DevDependencies Status

Install

You can install the Variety-cli globally in your system by calling:

npm install variety-cli -g

This will download the latest version from the NPM repository.

If you want to upgrade variety-cli to newest version, type the same command as for the installation: npm install variety-cli -g.

Docker

You can also run variety-cli in Docker using a pre-built image in Docker Hub. In this case, you'll generally want to run Variety against an external MongoDB host with the --host flag. See the example below for more information.

The variety-cli image is tagged in Docker Hub as objectrocket/variety, which you can run as follows:

docker run objectrocket/variety test/foo --host db.example.com --quiet

Any arguments after the image name are passed to variety-cli, just as if you were running it directly from the command-line.

Manually building the Docker image

First, build the image with docker build:

docker build -t variety .

This will build a Docker image tagged locally as variety, which you can run with:

docker run variety test/foo --host db.example.com --quiet

Run variety

Basic usage without any options. Database and collection names are separated by the / character:

variety database_name/collection_name [options]

Define your own query used to filter analysed documents:

variety test/users --query='{"bio":{"$exists":true}}'

The variety-cli uses HJSON to parse --query and --sort parameters and should be fault tolerant.

Nevertheless you should quote the JSON values properly. The quotes usage is little bit different for every operation system. Good description of JSON quoting can be found in the Amazon AWS documentation.

JSON output

If you want to post-process the Variety results in another tool, maybe you find useful the JSON output. This command should produce valid JSON output:

variety test/users --outputFormat='json' --quiet

Help

Print all available commands and options:

variety --help

Mongo shell params

The Variety-cli supports all the available parameters from the Mongo Shell. You can specify your --host, --port, --username, --password, --quiet and many other parameters. For all the available params of the mongo shell, see the Mongo documentation.

node variety-cli.js test/users  --host localhost --port 27017 --quiet

Example output

$ variety test/users  --host localhost --port 27017
MongoDB shell version: 3.0.0
connecting to: localhost:27017/test
Variety: A MongoDB Schema Analyzer
Version 1.4.1, released 14 Oct 2014
Using query of { }
Using limit of 5
Using maxDepth of 99
Using sort of { "_id" : -1 }
Using outputFormat of ascii
Using persistResults of false
Using collection of users
+------------------------------------------------------------+
| key                | types        | occurrences | percents |
| ------------------ | ------------ | ----------- | -------- |
| _id                | ObjectId     |           5 |    100.0 |
| name               | String       |           5 |    100.0 |
| bio                | String       |           3 |     60.0 |
| birthday           | Date         |           2 |     40.0 |
| pets               | Array,String |           2 |     40.0 |
| someBinData        | BinData-old  |           1 |     20.0 |
| someWeirdLegacyKey | String       |           1 |     20.0 |
+------------------------------------------------------------+

Proxy setting

If you are behind some proxy, you should configure proxy setting in your environment (to allow variety-cli download of the variety lib).

NPM proxy settings

Run this command (and change the proxy url to your needs):

npm config set https-proxy http://10.203.0.1:5187/

Node.js proxy settings

On the unix platforms this can be (temporary) achieved by calling:

export https_proxy=http://10.203.0.1:5187/

If you want to configure proxy for other node.js apps in the persistent way, add the command to your .bashrc or .bashprofile.

License

The MIT License (MIT)