markdown MongoDump和MongoRestore

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown MongoDump和MongoRestore相关的知识,希望对你有一定的参考价值。

# Mongo Dump commands

## Basic command to create a compressed dump file from a given monogodb host
```
mongodump -h hostname --port=port -d dbname --gzip --archive=path_to_archive_including_archive_file_name
```

To get the uncompressed version, exclude the --gzip flag

## If db needs credentials to access include username with -u parameter and -p for password
```
mongodump -h hostname --port=port -d dbname -u username -p "password" --gzip --archive=path_to_archive_including_archive_file_name
```

## To dump a specific collection add the --collection parameter
```
mongodump -h hostname --port=port -d dbname --collection collection_name --gzip --archive=path_to_archive_including_archive_file_name
```

## To query the collection or database before dumping add a --query parameter
The query parameter should be a JSON document. Ensure that the query parameter is enclosed in single quotes(e.g. ') for UNIX system and double quotes(e.g. ") fir Windows system
```
mongodump -h hostname --port=port -d dbname --collection collection_name -q '{query}'  --gzip --archive=path_to_archive_including_archive_file_name
```

以上是关于markdown MongoDump和MongoRestore的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB备份(mongodump)和恢复(mongorestore)

使用 mongodump 时遇到问题(4.4)

MongoDB-备份和恢复

MongoDB 备份(mongodump)与恢复(mongorestore)

MongoDB 备份(mongodump)与恢复(mongorestore)

mongodump与mongorestore的使用示例