JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 502
  • Score
    100M100P100Q88372F
  • License SSPL

MongoDB Toolkit

Package Exports

  • mongodb-toolkit
  • mongodb-toolkit/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mongodb-toolkit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

MongoDB Toolkit

MongoDB Toolkit is a utility library extracted from MongoDB Compass for exporting data, analyzing schemas, and more.

Features

  • Export Data: Export MongoDB data to CSV or JSON formats.
  • Schema Analysis: Analyze MongoDB collections to generate schema definitions.

Installation

To install MongoDB Toolkit, use npm:

npm install mongodb-toolkit

Usage

Exporting Data to CSV

const { createWriteStream } = require('fs');
const { MongoClient } = require('mongodb');
const { exportCSV } = require('mongodb-toolkit');

const mongoClient = new MongoClient('mongodb://localhost:27017');

const cursor = mongoClient
  .db('mydb')
  .collection('mycollection')
  .aggregate([{ $limit: 10 }]);

exportCSV(cursor, createWriteStream('output.csv'), {
  delimiter: ';',
  progressCallback: (idx, phase) => {
    console.log(phase, idx);
  },
})
  .catch((err) => {
    console.error(err);
  })
  .finally(() => {
    mongoClient.close();
    process.exit(0);
  });

Analyzing Schema

const { MongoClient } = require('mongodb');
const { analyzeSchema } = require('mongodb-toolkit');

const mongoClient = new MongoClient('mongodb://localhost:27017');

const cursor = mongoClient
  .db('mydb')
  .collection('mycollection')
  .aggregate([{ $limit: 10 }]);

analyzeSchema(cursor)
  .then((schema) => schema.getMongoDBJsonSchema())
  .then((jsonSchema) => {
    console.log(jsonSchema);
  })
  .catch((err) => {
    console.error(err);
  })
  .finally(() => {
    mongoClient.close();
    process.exit(0);
  });