MONGODB collection list

Hello everyone

I’m sorry to ask this question, because I think the answer is simple, but I can’t find anything on the net.

What is, please, the api that allows to list all the collections of the MONGODB database related to my meteor application.

Thank you for your help
YC

You can create a Meteor method which return the list of Mongodb collections.
Inside that method, you can get the raw database by calling:

const db = someCollection.rawDatabase();

or

const db = MongoInternals.defaultRemoteCollectionDriver().mongo.db

then you can have a list of collections by calling: db.getCollectionNames() method

// just something I found on the Internet but I think it works.

Thank you for your reply.
However I have a small problem, how do we import MongoInternals?

try this: import { MongoInternals } from "meteor/mongo";

async test() {
    const db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
    const collections = await db.listCollections().toArray();
    console.log("collections", collections);
  },
async test() {
    const db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
    const collections = await db.collections();
    debug(
      "collections",
      collections.map(c => c.collectionName),
    );
  },

I had already tried import { MongoInternals } from “meteor/mongo”;

import {Mongo} from "meteor/mongo";
import SimpleSchema from 'simpl-schema';
import {MongoInternals} from "meteor/mongo";

but “MongoInternals” is wrong with the message "Cannot resolve symbol ‘MongoInternals’ "
The internet is not too talkative on this topic…

what is your meteor version?

These codes run on server side only.

Version number 2.11.0
And of course it is implemented on the server side.
The problem is importing

You don’t need to import MongoInternals. It is global within Meteor.