Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get mongodb schema dump

I can take mongodb data backup but I am not sure about mongodb schama backup. Is there any way to take dump of MONGODB schema only not the data ?

like image 896
sakshi Avatar asked Feb 07 '17 07:02

sakshi


1 Answers

Here's how I did it:

mongodump --uri="mongodb://localhost/mydb" -o ./mydb-dump
find ./mydb-dump -name *.bson -exec truncate -s 0 {} \;

Explanation: I'm dumping the whole database, then truncating all the .bson files (which hold collection data) to zero bytes.

Limitation: Obviously, this is only practical if the source database is small, otherwise you're generating a huge data dump only to throw away most of it.

To restore this-

mongorestore --uri="mongodb://some-other-server/mydb" ./mydb-dump

If there's a better way to do this, I'd love to know what it is!

like image 149
Kip Avatar answered Oct 02 '22 02:10

Kip