We assume that you have a testing framework created.
Do Tools/NPM to open NPM console for this Rapise instance (note that global NPM will not work for your tests - you need to use this console).

CMD window shows up. Now do the command:
npm install mongodb

Now you are all set to start using the mongodb lib.
However, you cannot just call it directly because the library is async while Rapise test is always sync. So you need to use deasync library to wrap your calls, i.e.:
async function QueryMongoDb()
{
const { MongoClient } = require("mongodb");
// Create a new MongoClient
const client = new MongoClient(uri);
// TODO: all the code to query and return results
const query_result = ...
return return query_result;
}
// Always wrap your async calls into this function to run them from Rapise
function RunSync(fn) {
let resolved = false;
let value = null;
fn().then(
(val)=>
{
value=val;
resolved=true;
}
);
while(!resolved) require("deasync").runLoopOnce();
return value;
}
Then, when you need to call QueryMongoDb, you do it as follows:
const query_result = RunSync(QueryMongoDb);
If your implementation of QueryMongoDb needs some input parameters, it may be called as follows:
RunSync(async ()=> await QueryMongoDb(param1,param2,...));
// where param1 are actual values, i.e.:
const callResult = RunSync(async ()=> await QueryMongoDb("mongodb://localhost:27017",true));
We are attaching working testing framework that does query to a MongoDB. It also includes _MongoInit function, that does an npm install automatically when accessing the DB.
You may use it as a reference.