DEV Community

Discussion on: MongoDB Atlas Hackathon Help Thread

Collapse
 
iabdsam profile image
Abdul Samad

Is there a way to call a realm function from nodejs file using the MongoClient instance. If not, what is the right package realm or realm-web for doing this.

Collapse
 
iabdsam profile image
Abdul Samad

What I meant by MongoClient instance is the one which I used to query my Atlas database and collections.

Collapse
 
joellord profile image
Joel Lord

Yes, you can use the realm-web package for this. To call a serverless function called sum with the arguments 2 and 3, you would use the following code:

const functionName = "sum";
const args = [2, 3];
const result = await user.callFunction(functionName, args);
Enter fullscreen mode Exit fullscreen mode

You can find out more about how to use Realm functions in the documentation.

Collapse
 
iabdsam profile image
Abdul Samad

thanks it worked.