Is there a command to clear the history from within the mongo shell?
There should be a file called .dbshell in your home folder. Just delete it.
MongoDB terminal history is stored inside the ~/.dbshellfile. Just empty the .dbshell file
$ > ~/.dbshell
Versions of Windows mongo.exe earlier than 2.2.0 will save the .dbshell file in the mongo.exe working directory.
You can clear contents on the shell by Ctrl + L
Command history is stored in ~/.dbshell file.
For example, on a Unix-like system:
# Ensure an empty history file
echo "" > ~/.dbshell
# Remove rwx access to the history file
chmod 0 ~/.dbshell
If you're using MongoDB Shell as a standalone package, you will find the shell history file located in ~/.dbshell
If you're using the embedded MongoDB Shell inside MongoDB Compass, you will find the shell history file located in ~/.config/MongoDB Compass/MongoDB Compass/shell-history.json
Just empty the history file
Related
mongo maintains a history of commands in the .dbshell file.
Where in windows folder can we see this file?
In the user's home directory. <root>\Users\<username>
E.g. C:\Users\Jack
I have folders C:\testA01, C:\testA02 and C:\testB01, C:\testB02.
How to create a command to archive only folders with testA in their name?
"C:\Program Files\WinRAR\WinRAR.exe" a -r -u -rr8 -y C:\BACKUP\backup.rar C:\testA ?? \*.*
Windows command line interpreter does not support wildcards in folder paths. It is only possible to search for folders matching a pattern with DIR or FOR.
But take a look on text file WhatsNew.txt in program files directory of WinRAR version 5.30 or any later version. There can be read:
Folder wildcards are allowed in RAR command line in file names to
archive. For example:
rar a backup c:\backup\2015*\*
will archive all '2015*' folders in c:\backup. Use -r switch to search
for '2015*' also in c:\backup subfolders.
WinRAR v5.30 can be used on Windows XP and later Windows.
A command line for your backup task is for example:
"%ProgramFiles%\WinRAR\Rar.exe" u -cfg- -ep1 -idq -r -rr8 -y C:\BACKUP\backup.rar C:\testA*\*
For details on the used command u which is like command a with switch -u and the used switches see text file Rar.txt being the manual for the console version Rar.exe of WinRAR.
Of course you can also run from command line the GUI version, but one switch must be changed:
"%ProgramFiles%\WinRAR\WinRAR.exe" u -cfg- -ep1 -ibck -r -rr8 -y C:\BACKUP\backup.rar C:\testA*\*
The switch -ibck for running GUI version in background (minimized to system tray) is used instead of -idq which means for console version to run in quiet mode with only error messages printed into console window.
The commands and switches for the GUI version with some differences to console version are explained in help of WinRAR. Start WinRAR, click in menu Help on menu item Help topics, select tab Contents, open item Command line mode and read the pages listed below this list item.
I am new to mongo, and I am trying to install mongo on my windows system. I am following THIS tutorial, but when I do
C:\mongodb\bin\mongod.exe
my CMD gives me this output
2015-04-20T18:53:27.433+0500 I STORAGE [initandlisten] exception in ini
en: 29 Data directory C:\data\db\ not found., terminating
2015-04-20T18:53:27.436+0500 I CONTROL [initandlisten] dbexit: rc: 100
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db.
Create this folder
md \data\db
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotes,
for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
Read more in detail
I fixed the same using :
Create a folder data in
D:\project-workspace\mongodb\data
Then Create another folder db inside data
ie,
D:\project-workspace\mongodb\data\db
Then run the command
mongod --dbpath D:\project-workspace\mongodb\data\db
Make sure you have set environment variable for mongodb else browse C:\Program Files\MongoDB\Server\3.4\bin and then execute this =>
mongod.exe --dbpath E:\workspace\mongodb\data
I also faced the similar problem on windows, moreover, i dont have my environment variable set so i have to go to bin folder and run mongo. Below are the steps i followed
1) I created a folder on my desktop something like "C:\Desktop\data\"
2) In order to use mongo shell, you need to run mongo which is similar to a daemon on unix, so in windows, we can do it by opening a command prompt window and change directory to mongo\bin and run
mongod --dbpath C:\Desktop\data and left it runnning
3) I opened second command prompt window, did a change directory to C:\mongo\bin
and executed mongod, that's it
Because MongoDB does not know the directory DB.
Fixed Work for me.
Step 1: New Folder e.g. Run cmd
mkdir E:\workspace\mongodb\data
Step 2: Move to Root MongoDB path e.g. (cd .../MongoDB/.../bin/)
C:\Program Files\MongoDB\Server\3.4\bin>mongod.exe --dbpath E:\workspace\mongodb\data
Ok.
Also faced the same issue in windows. if --dbpath directory path does not contain spaces, do not include quotes. Removing quotes, when the path does not have space, resolved the issue.
I'm trying to install and run some basic commands on mongodb from this tutorial (on page 4).
So far,
I've downloaded the a 32-bit zip file from the mongodb download page.
I've unzip the file in the following locations home/user1 then renamed it to mongodb
I've create a folder called data then another one inside called db
I've created a file name mongodb.config containing the path of the folder where I want to store my data, which is mongodb/data/db.
But when I run the command to start the server:
user1#user1-VirtualBox: ~$ mongodb/bin/mongod --dbpath ~mongodb/data/db
I'm getting the following error:
bash: mongodb/bin/mongod : No such file or directory
Am I missing something?
Missing a '/', it should be ~/mongodb/data/db, not '~mongodb/data/db'
I want to write a long script for inserting and updating mongodb data.
Is it possible to call external js file that contains the script?
Is it possible to include another js file from the running js file?
Use Load function
load(filename)
You can directly call any .js file from the mongo shell, and mongo will execute the JavaScript.
Example : mongo localhost:27017/mydb myfile.js
This executes the myfile.js script in mongo shell connecting to mydb database with port 27017 in localhost.
For loading external js you can write
load("/data/db/scripts/myloadjs.js")
Suppose we have two js file myFileOne.js and myFileTwo.js
myFileOne.js
print('From file 1');
load('myFileTwo.js'); // Load other js file .
myFileTwo.js
print('From file 2');
MongoShell
>mongo myFileOne.js
Output
From file 1
From file 2
Another way is to pass the file into mongo in your terminal prompt.
$ mongo < myjstest.js
This will start a mongo session, run the file, then exit.
Not sure about calling a 2nd file from the 1st however. I haven't tried it.
Yes you can.
The default location for script files is data/db
If you put any script there you can call it as
load("myjstest.js") // or
load("/data/db/myjstest.js")
for running mutilple js files
#!/bin/bash
cd /root/migrate/
ls -1 *.js | sed 's/.js$//' | while read name; do
start=`date +%s`
mongo localhost:27017/wbars $name.js;
end=`date +%s`
runtime1=$((end-start))
runtime=$(printf '%dh:%dm:%ds\n' $(($runtime1/3600)) $(($secs%3600/60)) $(($secs%60)))
echo ############# $runtime $name.js completed ###########
echo "$name.js completed"
sync
echo 1 > /proc/sys/vm/drop_caches
echo 2 > /proc/sys/vm/drop_caches
echo 3 > /proc/sys/vm/drop_caches
done
To call external file you can use :
load ("path\file")
Exemple: if your file.js file is on your "Documents" file (on windows OS), you can type:
load ("C:\users\user_name\Documents\file.js")