Does MongoDB have a shell history file?
Asked Answered
F

4

41

Does MongoDB have something like a .bash_history file?

I recently typed in a long command, closed & re-opened the shell, and want to retrieve it.

Pressing up doesn't work as it seems that the history of the last shell is not accessible in the new shell.

I installed 1.8.1 with Homebrew. Is there a configuration variable I should set that will turn on MongoDB interactive shell history logging?

Here's my mongod.conf file:

# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb

# Only accept local connections
bind_ip = 127.0.0.1
# Enable Write Ahead Logging (not enabled by default in production deployments)
journal = true
Fade answered 22/4, 2011 at 2:20 Comment(1)
It should be on already. Did you check to see if you have a ~/.dbshell?Variation
V
50

Yes, its in ~/.dbshell as of version 1.8.1 which I am using. But this could be something they added in 1.7+ as from what I recall 1.6.5 does not have it.

Variation answered 22/4, 2011 at 3:6 Comment(2)
still at ~/.dbshell location with MongoDB shell version v4.0.6 on Debian LinuxGlacial
I can't find .dbshell for v6.0.7, but I found this file that appears to be the equivalent: ~/.mongodb/mongosh/mongosh_repl_historySiouan
P
2

of course yes,

it's in your home Path : ~/.dbshell like lobster1234 said. for windows you should check out the link https://docs.mongodb.com/manual/reference/program/mongo/#files

but beware, you should save the contents in other file (cat .dbshell >>Mongohistory.txt) after you have used mongo shell, becouse mongodb shell don't ganna save the whole commandes that you have taped in.

Puttee answered 30/7, 2017 at 13:12 Comment(0)
W
2

For windows, type the following in the powershell:

$ cat ~/.dbshell
Weichsel answered 29/11, 2018 at 21:20 Comment(0)
S
1

On Windows cmd you can type this command to see the history:

notepad %userprofile%\.dbshell

If you have VS code installed, this also works:

code %userprofile%\.dbshell
Sharrisharron answered 9/1, 2020 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.