mLabというmongodbのホスティングサービスを使っていて、そこからバックアップを取得する機会がありました。簡単に中身を確認できるのかなと思ったら、bson形式というバイナリー型のjsonフォーマットでデータが格納されており、viでもテキストエディタでも中身を見ることができませんでした。
A serialization format used to store documents and make remote procedure calls in MongoDB. “BSON” is a portmanteau of the words “binary” and “JSON”. Think of BSON as a binary representation of JSON (JavaScript Object Notation) documents. See BSON Types and MongoDB Extended JSON.
https://docs.mongodb.com/manual/reference/glossary/#term-bson
そんなとき便利だったのが、mLabにsandboxのDBを作ってそこにexportするという方法です。このようなコマンドでデータをリストアできるので、大変手軽でした。mongorestoreコマンドを使うには端末にmongodbがインストールされている必要があります。(macの場合brewでインストールすると簡単でした。)
1 |
mongorestore -h ds1111111.mlab.com:99999 -d DBNAME -u USERNAME -p PASSWORD /Users/username/FILENAME.bson |