0

With cmd in Win10, after terminate the mongo service, I got the error:

Error saving history file: FileOpenFailed Unable to fopen() file C:\Users\鍒樺簡鏂嘰.dbshell: Access is denied.

If use Powershell with Admin, I will get this strange file in C:\Users:

鍒樺簡鏂嘰.dbshell

So, the error occurs for the reason of my non-English name directory, so how to change the location of the .dbshell file in MongoDB? Thanks!

SpkingR
  • 965
  • 7
  • 14

1 Answers1

2

You can set it with environment variable 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:\>

see How to get to the Mongo shell history file or all history on Windows

Note, at startup the mongo shell reads file %USERPROFILE%\.mongorc.js, so you may have to move this file as well.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • Thanks a lot, I really appreciate your answer, I tried, but it does not work for me, win10, restarted, it seems that this env variable affects other apps like CCleaner. – SpkingR Feb 02 '21 at 04:15
  • Of course, it affects other application. You should set it only temporary in the command-line window where you start the mongo shell. – Wernfried Domscheit Feb 02 '21 at 06:27