Watch keynotes and sessions from, our virtual developer conference.

Get Error when I use bcdice

mongodb got error when i use bcdice

this.hosts = => host.toLowerCase());


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

const assert = require('assert');

// Connection URL

const url = 'XXXXXXXXX MY HOST';

// Database Name

const dbName = 'myproject';

// Use connect method to connect to the server

MongoClient.connect(url, function (err, client) {

    assert.equal(null, err);

    console.log("Connected successfully to server");

    const db = client.db(dbName);



var BCDice = require('bcdice').default;


function getInfo(gameType) {

    return BCDice.infoList.find(info => info.gameType === gameType);


function roll(command, gameType) {

    var bcdice = new BCDice();

    var [result, rands] = bcdice.roll(command, gameType);

    return {






console.log(roll('CC', 'Cthulhu'));

Hi @QQ_Zeix, welcome!

I’ve just tried your snippet code above without getting an error. My test ran successfully with bcdice v1.2.0 and MongoDB Node.JS driver v3.5.6.

I doubt that this is related to bcdice module, I suspect this is related more to the MongoDB connection URL that you’ve specified. Please check that you’re using a valid Connection String URI. Make sure you’re able to connect using mongo shell with the same connection string URI.

I would suggest to also review MongoDB Node.JS driver: Connect Tutorial. If you still having the same issue, please provide:

  • MongoDB Node.JS version
  • MongoDB server version