首页 > 解决方案 > 正确的连接方法。日志中不支持的警告

问题描述

我正在尝试找出使用本机驱动程序版本 3.10 和 Mongodb 服务器版本 3.6.5 连接到 Nodejs 中的 mongodb 的正确方法

我已经阅读了给出不同方法的文档,并且每种方法都会产生类似的警告。所有方法都有效,但每次连接到数据库时出现的警告使调试查询和其他代码问题变得更加困难。

我的连接代码是:

const MongoClient = require('mongodb').MongoClient
const url = `mongodb://${process.env.MONGO_HOST}:${process.env.MONGO_PORT}`
const opts = {
    useNewUrlParser: true,
    authMechanism: process.env.MONGO_MECH,
    authSource: process.env.MONGO_SRC,
    auth: {
        user: process.env.MONGO_USER,
        password: process.env.MONGO_PWD
    }
}
const Client = new MongoClient(url, opts)

此代码在日志中提供以下消息以及数据库上的每个操作

the options [socketOptions] is not supported
the options [read_preference_tags] is not supported
the options [dbName] is not supported
the options [servers] is not supported
the options [server_options] is not supported
the options [db_options] is not supported
the options [rs_options] is not supported
the options [mongos_options] is not supported
the options [mode] is not supported
the options [tags] is not supported
the options [preference] is not supported
the options [isValid] is not supported
the options [slaveOk] is not supported
the options [equals] is not supported
the options [toJSON] is not supported

标签: node.jsmongodb

解决方案


推荐阅读