首页 > 解决方案 > 如何更改 .dbshel​​l 历史文件位置

问题描述

在Win10中使用cmd,终止mongo服务后,出现错误:

保存历史文件时出错:FileOpenFailed Unable to fopen() file C:\Users\鍒桦简鏂叽叽.dbshel​​l:访问被拒绝。

如果将Powershell 与 Admin 一起使用,我将在以下位置获得这个奇怪的文件C:\Users

鍒樺簡鏂嘰.dbshell

那么,错误是由于我的非英文名称目录的原因而发生的,那么如何更改.dbshell文件在MongoDB中的位置?谢谢!

标签: mongodb

解决方案


您可以使用环境变量设置它USERPROFILE

c:\>set USERPROFILE=C:\Temp Files\IMP

c:\>mongo --norc
MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("b242c05d-68d5-48a5-ba06-43665f3eb2e9") }
MongoDB server version: 4.4.1
MongoDB Enterprise > db
test
MongoDB Enterprise > print("Hello World")
Hello World
MongoDB Enterprise > exit
bye

c:\>cat "C:\Temp Files\IMP\.dbshell"
db
print("Hello World")

c:\>

请参阅如何访问 Mongo shell 历史文件或 Windows 上的所有历史记录

请注意,在启动时 mongo shell 会读取 file %USERPROFILE%\.mongorc.js,因此您可能还必须移动此文件。


推荐阅读