无法停止记录应用程序中猫鼬放电的所有查询



我希望MongoDB停止记录node.js使用mongoose进行的所有查询。在我的CMD中,以命令"mongod--dbpath"C:\/data"--replSet rs "开始

我正在使用Node.js v10.16.3与猫鼬v.7.5

这就是我在server.js文件-中的连接方式

const options = {
auth: {
user: "tyd******",
password: "*****cgt"
},
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: true, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
bufferMaxEntries: 0,
connectTimeoutMS: 10000, // Give up initial connection after 10 seconds
socketTimeoutMS: 45000, // Close sockets after 45 seconds of inactivity
family: 4, // Use IPv4, skip trying IPv6
serverSelectionTimeoutMS: 5000, // Timeout after 5s instead of 30s
useUnifiedTopology: true,
};
mongoose.connect(dbConfig.url, options).then(
() => { 
console.log("Successfully connected to the database");
},
err => { 
/** handle initial connection error */ 
console.log('Could not connect to the database. Exiting now...', err);
process.exit();
}
);

请告诉我,如果有什么我可以在连接到mongoDb时添加到Option?

您可以在后台模式下启动mongod进程(使用--fork选项(,这样您就再也看不到日志了。因此,这将是您在CMD:中运行的命令

mongod --dbpath "C:/data" --replSet rs --fork

在使用Enterprise Edition时搜索"将MongoDB Enterprise Edition作为Windows服务启动"。

我需要使用cmdnet start MongoDB上的命令。对于stop,MongoDB as service命令是net stop MongoDB

如果mongod.conf配置正确,MongoDB服务器将成功启动。

文件mongod.conf可以在路径C:Program FilesMongoDBServer4.2bin找到,因为我的版本是4.2,所以你可以找到。

如果有人需要帮助,请访问链接

最新更新