0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MongoDBのデータダンプとリストア

Last updated at Posted at 2022-06-21

概要

MongoDBのデータダンプとリストアの方法について記載します。

ダンプ

mongodump -d {database} -c {collection} -o {OUTPUT_PATH} 
  • コレクションの指定が必要なければ -cの指定は不要
    • -cの指定がなければデータベース内のすべてのコレクションを取得する

リストア

mongorestore  -d {database} -c {collection} --dir {dir}

※注意

リストア時、-dオプション無しで、

mongorestore /tmp/mongotest/user.bson

のように実行することも可能であるが、その際、bsonファイルの親ディレクトリがデータベース名として認識されるので注意
(上記の例でいうとmongotestというデータベースが作成され、その中にuserコレクションがリストアされる)

また、user.metadata.jsonのようなjsonファイルがbsonと同ディレクトリ内に存在しない場合、Indexは登録されない
(jsonファイルにIndex情報を持っている)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?