Unable to Convert Find Command from Shell into NodeJS Query against Mongodb

I have a database and collection set up which has a BSONRegExp field named “myregex”. I have a number of entries each with different regex strings.

When I run the following against the database via shell I get a correct response back:

db.testcol.find(function() { return this.myregex.test(‘a’); } )

As you can see I am using the JavaScript test() method to check whether or not there is a match returned. I have attempted to migrate this over to NodeJS but I am unable to find any documentation as to how this query should be formed. I have been using the MongoDB Node.js Driver MongoDB Node.js Driver The following is the cloest I am able to get however it returns the entire collection and not just those matching the regex match to the inputted string (the string, in this case, being “a”).

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
    var dbo = db.db("Testingdb");

    dbo.collection("regextest").find( { $where: function() { return this.myregex.test('a') } } ).toArray(function (err,result) {
        if (err) {
        } else {

Any assistance or suggestions would be appreciated.

I tried to edit my initial post to correct the break-in script formatting but I believe I don’t have permission to do so. My apologies.