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

mongo-compare

v1.0.1

Published

CLI to make comparisons between documents in different collections and mongoDB databases

Downloads

5

Readme

npm npm Github Actions Status codecov Commitizen friendly AirBNB Style

Description

Mongo-compare is a CLI to make comparisons between documents in different collections and mongoDB databases.

Getting start

Installation

to install the cli you just need to execute the following command

# with npm
npm install -g mongo-compare

# or with yarn
yarn global add mongo-compare

Using the cli

  1. first you need to generate the base configuration of the cli, so to create the base config you execute the following command
mongo-compare -i
# or
mongo-compare --init

this command will ask for some parameters as the gif bellow

CLI in Action

option | description ----------------------------------- | -------------------------------------------- output format | format that the results will be generated mongo-compare config file | name and path of the config file (default: mongo-compare-config.json) folder path to output the results | the path where the result will be generated (default: mongo-compare-results) override mongo-compare config file | if the config file already was generated before, you could override it mongo-compare config file extension | extension of the config file (default: json) remove folder with actual results and create it again | if the folder already was generated before, you could override it

In the final the folder where the results will be exported will be created and a file with the config will be generated with a content as the example bellow:

{
  "outputFormat": "json", // format that the compare results will be generated
  "outputResultFolderPath": "mongo-compare-results", // the folder where the results will be exported
  "collectionsConfig": [] // the list of collections that will be compared
}
  1. now you just need to populate the configuration on file just like the following example:
{
    "outputFormat": "json",
    "outputResultFolderPath": "mongo-compare-results",
    "collectionsConfig": [
        {
            "currentCollection": {
                "url": "mongodb://127.0.0.1:62391/jest?", // url of running mongoDb
                "dbName": "jest", // database name
                "collectionName": "test1", // collection name
                "filterBy": "name", // the name of field that make the document unique on collection, could be and array
                "ignoreFields": ["_id"] // fields that will be ignored on compare [optional]
            },
            "previousCollection": {
                "url": "mongodb://127.0.0.1:62391/jest?",
                "dbName": "jest",
                "collectionName": "test2",
                "filterBy": "name"
            }
        },
    ]
}

field | description ----------------------------------- | -------------------------------------------- outputFormat | format that the results will be generated outputResultFolderPath | folder path where the results will be generated collectionsConfig | list of collections that will be compared, that options of config is bellow url | url of running mongoDb dbName | database name collectionName | collection name filterBy | the name of field that make the document unique on collection, could be and array if you need to filter by two or more fields to make a document unique on collection ignoreFields | fields that will be ignored on compare (default ["_id"])

  1. the next step is run the command to execute the compare and generate the results
# if you dont pass the path of config file it will use the default: mongo-compare-config.json
mongo-compare
# to pass the path of config file
mongo-compare -c <path of the config file>
# or
mongo-compare --config <path of the config file>

the results will be generated on the folder specified on config file, you can see the progress step by step on the logs, and the result will be something just like this:

[
    {
        "collectionName": "test1",
        "differences": {
            "diffKeys": ["prop1"],
            "currentDocument": { "dbName": "jest", "prop1": 1, "name": "test" },
            "previousDocument": { "dbName": "jest", "prop1": 2, "name": "test" }
        }
    },
    {
        "collectionName": "test3",
        "differences": {
            "diffKeys": ["prop1"],
            "currentDocument": { "dbName": "jest", "prop1": 1, "name": "test" },
            "previousDocument": { "dbName": "jest", "prop1": 2, "name": "test" }
        }
    },
    {
        "collectionName": "test3",
        "differences": {
            "diffKeys": [],
            "currentDocument": { "dbName": "jest", result: 'not exists', },
            "previousDocument": { "dbName": "jest", "prop1": 2, "name": "test" }
        }
    }
]

field | description ---------------------------------- | -------------------------------------------- collectionName | name of the collection differences | field with the difference details diffKeys | the fields that have the differences currentDocument | the actual document previousDocument | the previous document dbName | the name of the database rest of the fields of document | rest of fields of the document that has the difference result | if the document exists on just a collection this field will be returned with the value 'not exists'

Using the package programmatically

you can also use the package programmatically, just install the package and import it to use the methods available, to see how to use the methods just execute the bellow and the documentation will be generated with jsdoc.

# with npm
npm run docs
# with yarn
yarn docs

executing the Tests

to execute the test run the following command:

# with npm
npm test
# with yarn
yarn test