# MongoDB driver warning

**URL:** <https://forum.codewithmosh.com/t/mongodb-driver-warning/15757>\
**Category:** Node\
**Created:** [October 9, 2022, 8:25am UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757 "2022-10-09T08:25:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nav\_pb03](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nav\_pb03](https://forum.codewithmosh.com/u/nav_pb03)\
**Post date:** [October 9, 2022, 8:25am UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/1 "2022-10-09T08:25:45Z")

</div>

Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.  
(Use `node --trace-warnings ...` to show where the warning was created)

My code in db.js

const mongoose = require(‘mongoose’);  
const winston = require(‘winston’);  
const config = require(‘config’);

module.exports = function() {  
const db = config.get(‘db’);  
mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })  
.then(() =\> winston.info(`Connected to ${db}...`));  
}

My code in logging.js

const winston = require(‘winston’);  
require(‘winston-mongodb’);  
require(‘express-async-errors’);  
const config = require(‘config’);

module.exports = function() {  
winston.exceptions.handle(  
new winston.transports.Console({ colorize: true, prettyPrint: true }),  
new winston.transports.File({filename: ‘uncaughtExceptions.log’})  
);

```
process.on('unhandledRejection', (ex) => {
    throw ex;
});

winston.add(
    new winston.transports.MongoDB({
      db: 'mongodb://localhost/vidly',
      level: 'error',
      options: { useUnifiedTopology: true },
    })
  );    
winston.add(new winston.transports.File({filename: 'logfile.log'}));
winston.add(new winston.transports.MongoDB({
    db: 'mongodb://localhost/vidly',
    level: 'info'
}));

```

}

Please note I am using mongoose and not MongoClient anywhere

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [October 9, 2022, 11:16am UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/2 "2022-10-09T11:16:30Z")

</div>

```auto
winston.info(Connected to ${db}...));

```

should be

```auto
winston.info(`Connected to ${db}...`));

```

---

<div class="post-metadata">

**Author:** ![nav\_pb03](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nav\_pb03](https://forum.codewithmosh.com/u/nav_pb03)\
**Post date:** [October 9, 2022, 11:35am UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/3 "2022-10-09T11:35:10Z")

</div>

> [@onlyhasbi](#):
>
> `winston.info(`Connected to ${db}…`));`

> [@onlyhasbi](#):
>
> `winston.info(`Connected to ${db}…`));`

it is:  
winston.info(`Connected to ${db}...`));

it is just not showing in here

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [October 9, 2022, 12:15pm UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/4 "2022-10-09T12:15:26Z")

</div>

what version of Winston you’re using? is it the latest?

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [October 9, 2022, 12:20pm UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/5 "2022-10-09T12:20:00Z")

</div>

if you’ve reading the documentation of the latest Winston. The recommended way to use `winston` is to create your own logger. The simplest way to do this is using `winston.createLogger`

---

<div class="post-metadata">

**Author:** ![nav\_pb03](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nav\_pb03](https://forum.codewithmosh.com/u/nav_pb03)\
**Post date:** [October 9, 2022, 1:03pm UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/6 "2022-10-09T13:03:34Z")

</div>

Ok, and after creating the logger can you please help me with the next steps?

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [October 9, 2022, 2:05pm UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/7 "2022-10-09T14:05:39Z")

</div>

here is how I define my logger

```auto
const { createLogger, format, transports } = require("winston");
const { combine, timestamp, printf, simple } = format;
// require("winston-mongodb");

const logFormat = printf(({ level, message, timestamp }) => {
  return `${level}: ${timestamp} ${message}`;
});

const logger = createLogger({
  transports: [
    new transports.Console({
      level: "debug",
      handleExceptions: true,
      handleRejections: true,
      format: simple(),
    }),
    new transports.File({
      level: "info",
      filename: "loginfo.log",
      format: simple(),
    }),
    new transports.File({
      level: "error",
      filename: "exception.log",
      handleExceptions: true,
      handleRejections: true,
      format: combine(timestamp({ format: "DD/MM/YYYY HH:mm:ss" }), logFormat),
    }),
  ],
});

module.exports = logger;
module.exports.stream = {
  write: function (message) {
    logger.info(message.replace(/(\r\n|\n|\r)/gm, ""));
  },
};

```

---

<div class="post-metadata">

**Author:** ![nav\_pb03](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nav\_pb03](https://forum.codewithmosh.com/u/nav_pb03)\
**Post date:** [October 9, 2022, 2:16pm UTC](https://forum.codewithmosh.com/t/mongodb-driver-warning/15757/8 "2022-10-09T14:16:36Z")

</div>

Thanks did the same but still facing the above issue
