Giter VIP home page Giter VIP logo

mongo-to-s3's Introduction

mongo-to-s3 (WIP)

Build Status codecov.io NPM version

var AWS       = require("aws-sdk");
var MongoToS3 = require("mongo-to-s3");
var through = require("through");

var s3 = new AWS.S3({
  accessKeyId: "myAccessKey",
  secretAccessKey: "mySecretAccessKey",
  region: "us-east-1"
});

mongoToS3 = new MongoToS3(s3);

mongoToS3.createS3Sink({
  s3: {
    Bucket: "myBucket",
    Key: "myKey",
    ACL: "public-read"
  },
  chunkUploadSize: 5242880, //5MB
  workingDirectory: "/tmp"
}, function(err, myS3Sink) {
  /*
   * myS3Sink is a writable stream that batch uploads
   * data into s3 using their multipart upload api
  */

  mongoToS3.fromMongo([{
    //anything accepted by 'mongoexport'
    exportOptions: "-h localhost:27017 -d database -c collection",
    workingDirectory: "/tmp" //some writable path on your machine
  }],
  function(err, exports) {

    exports
      .streams
      .pipe(through(function(chunk, enc, cb) {
        //some processing step
        console.log("Processing:", chunk);
        this.push(chunk);
        cb();
      }))
      .pipe(myS3Sink);
  
    exports.resume();
  });
});


/*
 *  If you want to process data from multiple mongoexport commands
 *  just pass in more configuration objects into `fromMongo`
*/
  mongoToS3.fromMongo([
    {
      exportOptions: "-h localhost:27017 -d database -c collection1",
      workingDirectory: "/tmp"
    },
    {
      exportOptions: "-h localhost:27017 -d database -c collection2",
      workingDirectory: "/tmp"
    }
  ],
  function(err, exports) {

    exports
      .streams
      .pipe(through(function(chunk, enc, cb) {
        //both collection 1 and collection 2 are joined here.
        this.push(chunk);
        cb();
      }))
      .pipe(someWritableStream);

    exports.resume();
  });

/*
 * Sometimes you might want to process mongoexport results in
 * separate processes to increase throughput.
*/
  mongoToS3.fromMongo([
    {
      exportOptions: "-h localhost:27017 -d database -c collection1",
      workingDirectory: "/tmp"
    },
    {
      exportOptions: "-h localhost:27017 -d database -c collection2",
      workingDirectory: "/tmp"
    }
  ])
  .thoughPipeline(__dirname + "/somePipeline.js")
  .pipe(someWritableStream);

/*
 * `throughPipeline` takes the pathname of a file that exports a Duplex (or Transform) stream.
 * Each mongoexports stream gets its own processing pipe that runs in an external
 * process. The results are then aggregated into the main process. In the above example both
 * collection1 and collection2 are uploaded to s3 after being processed by the stream exported
 * by /somePipeline.js
*/

mongo-to-s3's People

Contributors

cainus avatar bttmly avatar stuartreavley avatar peterkhayes avatar

Stargazers

Igor Agenor Piovezan avatar SACHIN TRIPATHI avatar Matt Saddington avatar Dawid Tomkalski avatar samchaudhary avatar Paul K. avatar Blake avatar  avatar Will Keleher avatar  avatar  avatar  avatar

Watchers

Tom Aylott avatar Angela avatar Bernie Zang avatar Isaac Weinhausen avatar Victor avatar Sergio Rafael Gianazza avatar  avatar Jason Whyne avatar Blake avatar Leonardo Garcia Crespo avatar Dan Gilbert avatar Chris Frank avatar Hassan Shahid avatar  avatar Melissa Yu Dirdo avatar Robert Messerle avatar Will Keleher avatar James Cloos avatar  avatar Ger avatar Nicole avatar Nick F avatar Byron avatar  avatar  avatar Jet Zhou avatar Lijana Saniukaite avatar Riley Shaw avatar Juan Belej avatar Alex Li avatar  avatar Rutvij Shah avatar Mike Chang avatar  avatar Greg Dyer avatar Aman Gupta avatar  avatar  avatar Tyler Eastman avatar  avatar Tim avatar Cristin Quealy avatar Manoj Lamba avatar Brian Maxwell avatar Jacqueline Sloves avatar John Master avatar April Ablon avatar Adrian Falleiro avatar Jenna O'Rourke avatar Igor Agenor Piovezan avatar  avatar  avatar Vieira Neto avatar  avatar  avatar  avatar Michael Luther avatar  avatar Evan Jones avatar Meg Bowman avatar  avatar Alex Morelli avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.