I want migrate old Mongodb2.6.8 database to new Mongodb4.4. So I tried mongodump to backup below "okapp" database.
[okapp@centos101 bin]$ ./bin/mongo localhost:27018
MongoDB shell version: 2.6.8
connecting to: localhost:27001/test
> show dbs
admin (empty)
okapp 6.497GB
ca423 0.031GB
local 0.031GB
>
As you can see okapp size is 6.497GB. But after i run below:
./mongodump -h localhost:27001 -d okapp
And I will get a the dump:
2021-11-02T15:47:14.550+0100 DATABASE: okapp to dump/okapp
2021-11-02T15:47:14.550+0100 okapp.system.indexes to dump/okapp/system.indexes.bson
2021-11-02T15:47:14.551+0100 5 documents
2021-11-02T15:47:14.551+0100 okapp.findjobsee to dump/okapp/findjobsee.bson
2021-11-02T15:47:14.551+0100 10 documents
2021-11-02T15:47:14.551+0100 Metadata for okapp.findjobsee to dump/okapp/findjobsee.metadata.json
2021-11-02T15:47:14.552+0100 okapp.findtasksee to dump/okapp/findtasksee.bson
2021-11-02T15:47:14.552+0100 0 documents
2021-11-02T15:47:14.552+0100 Metadata for okapp.findtasksee to dump/okapp/findtasksee.metadata.json
2021-11-02T15:47:14.552+0100 okapp.findresultsee to dump/okapp/findresultsee.bson
2021-11-02T15:47:14.614+0100 2937 documents
2021-11-02T15:47:14.614+0100 Metadata for okapp.findresultsee to dump/okapp/findresultsee.metadata.json
2021-11-02T15:47:14.615+0100 okapp.findjobarchivesee to dump/okapp/findjobarchivesee.bson
2021-11-02T15:47:14.618+0100 751 documents
2021-11-02T15:47:14.618+0100 Metadata for okapp.findjobarchivesee to dump/okapp/findjobarchivesee.metadata.json
[okapp@centos101 somedir]$ cd ./mongodb-linux-x86_64-2.6.8/dump/okapp
[okapp@centos101 somedir]$ du -sh okapp
7.7MB okapp
[okapp@centos101 somedir]$ cd ./mongodb-linux-x86_64-2.6.8/dump/okapp
[okapp@centos101 okapp]$ du -sh *
316K findalljobarchivesee.bson
4.0K findalljobarchivesee.metadata.json
4.0K findalljobsee.bson
4.0K findalljobsee.metadata.json
7.4M findallresultsee.bson
4.0K findallresultsee.metadata.json
0 findalltasksee.bson
4.0K findalltasksee.metadata.json
4.0K system.indexes.bson
[okapp@centos101 okapp]$
[okapp@centos101 okapp]$
Note: i've checked the collections in the Mongodb
> db.findjobarchivesee.count()
751
> db.findjobsee.count()
10
> db.findresultsee.count()
2937
> db.findtasksee.count()
0
> db.system.indexes.count()
5
Anyone know why the size shrink too much? It was 6.497GB in database, but it just a 7.7 MB after mongodump.
I think there are a few things that contribute to the difference:
show dbs
includes empty space in the files, which may be due to documents being deleted.mongodump
does not export index data. It exports the information that mongorestore will need in order to recreate the index at restore time.