mongodb - mongodump is not defined
Asked Answered
M

6

9

I am a newbie to mongodb. I am trying to take a backup of my database using mongodump. But whenever I use this command I get the below error

Referenceerror: mongodump is not defined

I tried creating a new user with all the roles but still I get the same error. Should I add a specific role to take a backup? Or am I doing something wrong?

Murphree answered 19/1, 2016 at 11:42 Comment(5)
Are you running the mongodump command inside mongo shell or in the terminal?Forensics
I tried in both the ways. Still getting the sameMurphree
mongodump is not a mongo shell command, it is a separate mongodb utlity which usually can be found under mongodb bin folder.Forensics
@Forensics Thanks! Then how can I use mongodump?Murphree
Possible duplicate of Mongodb's "mongodump" command, javascript execution errorForensics
H
14

'mongodump' is a command/tool which is included in the 'mongodb-tools' package. If you don't have this package installed on your machine, it makes sense that it is not defined. The mongodb-tools also provide several other tools used for importing and exporting DBs (like mongorestore).

That being said, 'mongodump' is not a mongo-shell command, you shouldn't be using it in mongo-shell. It's a whole different command that you would be executing just like you execute 'mongod' or 'mongo' etc.

Highline answered 3/1, 2019 at 8:21 Comment(0)
A
4
  • One simple way is to right-click mongodump.exe and "Run as administrator". It will create dump folder in bin of your mongodb home containing all database backups.
  • If you want to go with commands, open cmd as administrator and go to bin of your mongodb where you'll be able to fire commands such as mongorestore, mongodump etc. with intended parameters e.g for specific db or interact with remote mongodb.

tested on (v4.2.3)

Note: many folks try to execute these commands in mongod where you can execute queries which is wrong, these tools needs to be used separately.

Amero answered 25/4, 2020 at 12:37 Comment(0)
G
3

Here ar e 2 simple exemples for a full backup using authentication and without

mongodump -h hostname -v -u sys_account -p ys_password --authenticationDatabase admin --out folder_location_for_backup

if no authentication

mongodump -h hostname -v --out folder_location_for_backup

here are the mongorestore commands as well

mongorestore -h hostname -v -u admin_user -p admin_password --authenticationDatabase admin --dir folder_location_where_backup_is_located

if no authentication

mongorestore -h hostname -v  --dir folder_location_where_backup_is_located
Garett answered 19/1, 2016 at 19:7 Comment(0)
C
2

for windows, you need to start executable file by running following command

"C:\Program Files\MongoDB\Server\3.4\bin\mongodump.exe" --db your_database_name

Above command will export your database to dump folder. This folder will be located where you have kept your "data" folder. If you use default "data/db" folder then it will be there but if you use different location then it will be kept over there. This command must be run in normal command prompt, not in mongo shell. It is executable not mongo shell command. Official docs link is here.

Chifforobe answered 25/9, 2017 at 7:12 Comment(0)
P
0

Download MongoDB Command Line Database Tools .The mongodump tool is part of the MongoDB Database Tools package.

Pasha answered 16/11, 2022 at 14:52 Comment(0)
D
-1

There are great chances that mongodump is being performed under Mongo Shell

mongodump should be run directly on command line or terminal (NOT inside mongo shell)

For creating dump of database

 mongo --db database_name

For creating dump of any collection of database

mongo --db databas_name --collection collection_name
Delineator answered 19/10, 2020 at 7:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.