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-to-elastic-dump

v2.0.7

Published

Dump records from mongo to elastic

Downloads

51

Readme

Mongo To Elastic Dump

mongo-to-elastic-dump is a command line tool for dumping data from mongodb to elasticsearch.

  • command line tool for multi-utility
  • Feature to transform data before dumping
  • Both Insert and Update document
  • https://www.npmjs.com/package/mongo-to-elastic-dump
  • https://github.com/sameer17cs/mongo-to-elastic-dump

Installation

Requires Node.js to run. Works best with mongodb v4.x and elasticsearch v6.x, v7.x

$ npm install mongo-to-elastic-dump
$ npm install mongo-to-elastic-dump -g

Use it as command line

$ cd /path/to/library
$ npm link

Building for source

For production release:

$ git clone https://github.com/sameer17cs/mongo-to-elastic-dump
$ cd mongo-to-elastic-dump
$ npm install

Use as tool

Once installed, you can use it as command line tool

$ mongo-to-elastic-dump [--options]

Options are:

  • m_host String

    • mandatory
    • mongodb host uri (uri:port)
  • m_db String

    • mandatory
    • mongodb database to dump from (source)
  • m_collection String

    • mandatory
    • mongodb collection to dump from
  • m_limit Number

    • optional
    • Per batch limit for mongo query
    • Default: 500
  • m_query String

    • optional
    • Mongodb query to extract dump
    • Default: {}
    • Example: {"dump": true}
  • m_fields String

    • optional
    • Mongodb Document Fields to dump
    • Default: null (i.e. all fields)
    • comma separated string
    • Example: field1, field2, field3
  • m_skip_id BSON String

    • optional
    • Mongodb document id to start from.
    • BSON string
    • Useful when you dont want to begin dumping from start
    • If your command stops while running, you can take the next skip id to run from log (log will print next id to run)
  • e_host String

    • mandatory
    • Elasticsearch uri (localhost:9200)
  • e_auth Object

    • Optional
    • Elasticsearch authentication
  • e_index String

    • mandatory
    • Elastic index to insert/update documents
  • e_doc_id String

    • mandatory
    • Document Primary key
    • JSON Document field name, whose value will be used as primary id in elasticsearch
  • m_transform relative path of transform.js

    • optional
    • filename.js should export a function named 'transform'
    • This function should transform and return the doc
    • Example: transform-examples/timestamp-created.js
  • e_update_key updatekey [, isPrimary ]

    • optional
    • Use when you want to update elasticsearch docs by primary key or non-primary key.
    • It is JSON Document field name, whose value will be used to match document for update.
    • updateKey key field should be present in both elasticsearch and mongodb
    • Options like ---m_query, -m_fields, --m_transform are valid
    • Will update multiple docs (if found)
    • If elasticsearch throws error, try setting lower value for m_limit
    • isPrimary - default: false
      • [OPTIONAL]
      • Set true when updatekey is THE elasticsearch primary key. It is faster.
      • Set false when updatekey is NOT elasticsearch primary key. It is slow.
      • When false, updateKey will be searched in elasticsearch using term query. Works best when updateKey is mapped as keyword
    • Example --e_update_key updateKey | --e_update_key updateKey,true
  • e_action String

    • optional
    • Default: index
    • Elasticsearch action to perform on document: index OR create
  • attempts Number

    • optional
    • Default: -1
    • Elasticsearch number of attempts to retry on failure (-1 for infinite)
Example

UPSERT DOCS

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_doc_id uuid

UPSERT SELECT DOCS BY MONGODB QUERY

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_doc_id uuid  --m_query '{}'

UPSERT SELECT FIELDS

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_doc_id uuid  --m_fields field1,field2,field3

UPSERT TRANSFORMED DOCS

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_doc_id uuid --m_transform transform.js

UPDATE DOCS IN ELASTIC BY GIVEN PRIMARY updatekey

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_update_key updatekey,true

UPDATE DOCS IN ELASTIC BY GIVEN NON-PRIMARY updatekey (should be mapped in elasticsearch)

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_update_key updatekey

UPDATE DOCS IN ELASTIC BY TRANSFORM

mongo-to-elastic-dump --m_host localhost:27017 --m_db testdb --m_collection testcoll --e_host localhost:9200 --e_index testindex --e_update_key updatekey --m_transform transform.js

License

MIT