williamkapke / mongo-mock

Let's pretend we have a real MongoDB
MIT License
240 stars 75 forks source link

tested app unable to connect to mock db #155

Open chengtangzheng2021 opened 2 years ago

chengtangzheng2021 commented 2 years ago

The line of process.env.MONGO_URL = uri; passing connection string to the tested app, in the below connection code, but the app using this connection url get connection refused.

const connect = async () => { var mongodb = require('mongo-mock'); var uri = 'mongodb://localhost:27017/myproject'; process.env.MONGO_URL = uri; process.env.MDB_NAME = 'PricerDB_EMEA'; var MongoClient = mongodb.MongoClient; MongoClient.connect(url, {}, function (err, client) { db = client.db(); var collection = db.collection('adjustmentsDetails'); collection.insertOne({ "startOn": new Date("2020-07-10 15:00:00.000") }) }) }

LinusU commented 1 year ago

get connection refused.

This library doesn't actually connect to anything, so it shouldn't be able to give you "connection refused"

Could you post the stacktrace of the error you are getting?