Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
Typescript + MongoDB + Prisma: List all databases programmatically

Is there any way to list all databases on a MongoDB server via Prisma programmatically with typescript?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the $runCommandRaw prisma function to list all the databases.

main.ts

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient({
  log: ['query'],
});

async function main() {
  const output = await prisma.$runCommandRaw({ listDatabases: 1 });

  console.log(output);
}

main()
  .catch((e) => {
    throw e;
  })
  .finally(async () => {
    await prisma.$disconnect();
  });

Here's the output:

> ts-node index.ts

{
  databases: [
    { name: 'prisma', sizeOnDisk: 57344, empty: false },
    { name: 'sample_airbnb', sizeOnDisk: 55226368, empty: false },
    { name: 'sample_analytics', sizeOnDisk: 9609216, empty: false },
    { name: 'sample_geospatial', sizeOnDisk: 1437696, empty: false },
    { name: 'sample_mflix', sizeOnDisk: 56508416, empty: false },
    { name: 'sample_restaurants', sizeOnDisk: 8863744, empty: false },
    { name: 'sample_supplies', sizeOnDisk: 1191936, empty: false },
    { name: 'sample_training', sizeOnDisk: 62578688, empty: false },
    { name: 'sample_weatherdata', sizeOnDisk: 3694592, empty: false },
    { name: 'admin', sizeOnDisk: 339968, empty: false },
    { name: 'local', sizeOnDisk: 4137603072, empty: false }
  ],
  totalSize: 4337111040,
  totalSizeMb: 4136,
  ok: 1
}

Please make sure that to run listDatabases command you need to be on the admin database, so your connection string should point to admin database

Example:

DATABASE_URL="mongodb+srv://username:password@cluster0.souw3.mongodb.net/admin"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!