Run mongo shell commands from MongoDB Realm Functions

This may be a very basic question, but is it possible to run mongo shell commands from the Realm Functions? There are plenty of mongo shell commands that I’d like to run, but I don’t see the relation between the mongo shell and the MongoDB Realm Functions / Realm Administration API.

For instance, the listCollections function: https://docs.mongodb.com/manual/reference/command/listCollections/. Every research on that leads me to the mongo shell.

@Jean-Baptiste_Beau Can you try the node.js driver? It has a collections method -
https://mongodb.github.io/node-mongodb-native/markdown-docs/collections.html#list-collections

@Ian_Ward using the node.js driver in Realm Functions yields the error:

MongoDB Node.js Driver is not supported. Please visit our MongoDB Realm documentation.

how about this -
https://docs.mongodb.com/realm/admin/api/v3/#post-/groups/{groupid}/apps/{appid}/services/{serviceid}/commands/{commandname}

Perhaps @Jean-Baptiste_Beau you can try to load the MongoDB js driver using external dependency and then require it in function.

https://docs.mongodb.com/realm/functions/upload-external-dependencies/
This said you will still have to provide atlas connection user and uri but those could be stored as secrets.

@Pavel_Duchovny I uploaded the driver and its dependencies, however I still get the error when I do:

var MongoClient = require('mongodb').MongoClient;

@Ian_Ward what would be the service name? Could you show me an example with listCollections please?

@Jean-Baptiste_Beau POST /groups/ **{groupId}** /apps/ **{appId}** /services/ **{serviceId}** /commands/ **{commandName}**

{commandName} should be list_collections

Did you ever get this to work? Do you have example code to share?

No unfortunately I couldn’t get this to work. Since I only needed the listCollections methods, I ended up hardcoding an array with all the object types in my database and looping through this instead.

Are you figure this out? I’m stuck in this for two days :frowning:

It whould be better if you can explain more