vladholubiev / mongo-move

Move docs between MongoDB collection, matching criterias, and w/ optional transformer

Home Page:https://stackoverflow.com/a/27041518/2727317

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mongo Move CircleCI node (tag)

Move documents between MongoDB collection. Applying async transforms, optionally.

Install

$ yarn add mongo-move

Usage

import {MongoClient} from 'mongodb';
import {moveDocs} from 'mongo-move';

const db = await MongoClient.connect('mongo-url');

await moveDocs({
  fromCollection: db.collection('coll-a'),
  toCollection: db.collection('coll-b'),
  selector: {userId: 'some-user-id'},
  projection: {name: 0},
  transformerFn: async doc => {
    doc.movedAt = new Date();
    return doc;
  },
  chunkSize: 1000,
});

Publish

$ git checkout master
$ yarn version
$ yarn publish
$ git push origin master --tags

License

MIT © Vlad Holubiev

About

Move docs between MongoDB collection, matching criterias, and w/ optional transformer

https://stackoverflow.com/a/27041518/2727317

License:MIT License


Languages

Language:TypeScript 93.7%Language:JavaScript 6.3%