KeplerGrid guide

mongodump vs mongoexport

Compare a BSON dump and a JSON Lines export of the same MongoDB collection and see what happens to a secondary index.

Choose the tool for the job

Use mongodump and mongorestore when you need to restore a BSON dump and its collection metadata. Use mongoexport and mongoimport to exchange documents as JSON or CSV. For production backup needs, evaluate MongoDB’s supported backup options for your deployment.

Create the same starting data

Install MongoDB Database Tools. In mongosh, make a practice collection with one document and a secondary index.

const orders = db.getSiblingDB("keplergrid_transfer").orders;
orders.insertOne({
  _id: ObjectId("67a000000000000000000101"),
  status: "paid",
  orderedAt: ISODate("2026-02-01T10:00:00Z"),
  total: NumberDecimal("28.50")
});
orders.createIndex({ status: 1 }, { name: "status_1" });

Dump and restore under a new database name

Use an empty output directory and a fresh destination on your local practice instance. The restore recreates the secondary index from the metadata included in the dump.

mongodump --uri="mongodb://127.0.0.1:27017"   --db=keplergrid_transfer --collection=orders --out=./practice-dump
mongorestore --uri="mongodb://127.0.0.1:27017"   --nsFrom="keplergrid_transfer.orders" --nsTo="keplergrid_restored.orders"   ./practice-dump

Export and import just the documents

Run these commands with a fresh destination collection. Canonical Extended JSON preserves the example document’s BSON types through import.

mongoexport --uri="mongodb://127.0.0.1:27017"   --db=keplergrid_transfer --collection=orders --jsonFormat=canonical   --out=./orders.jsonl
mongoimport --uri="mongodb://127.0.0.1:27017"   --db=keplergrid_imported --collection=orders --file=./orders.jsonl

In KeplerGrid, check both destinations in the Documents and Indexes tabs. Both contain the order. keplergrid_restored.orders has the status_1 index. keplergrid_imported.orders has its default _id_ index.

Import JSON Lines in KeplerGrid · Convert a BSON file to JSON Lines · MongoDB mongoexport reference