Is it normal that mongodump shows `skipping collection: my_db.my_collection.$_id_`?

691 views Asked by At

I tried to mongodump my db:

sudo mongodump -v --dbpath /var/lib/mongodb --out ~/backups/mongodb_dump/

but each collection had interesting output (it was verbose), there are some interesting lines:

Tue Dec  3 06:32:32 [tools] query my_db.my_collection nreturned:101 reslen:43408 0ms
Tue Dec  3 06:32:32 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:8565 reslen:4194597 77ms
Tue Dec  3 06:32:32 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:8053 reslen:4194704 75ms
Tue Dec  3 06:32:32 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:7936 reslen:4194704 82ms
Tue Dec  3 06:32:32 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:7932 reslen:4194524 83ms
Tue Dec  3 06:32:32 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:9201 reslen:4194491 201ms
Tue Dec  3 06:32:33 [tools] getmore my_db.my_collection cursorid:7364310293552401077 nreturned:7253 reslen:3078796 544ms
         49041 objects
Tue Dec  3 06:32:33 [tools]     skipping collection: my_db.my_collection.$_id_
    flickr-app-development-production.download_stats to /home/user/backups/mongodb_dump/my_db/my_collection.bson

What does it mean: skipping collection: my_db.my_collection.$_id_, why id field? Does it mean some data wasn't dumped, or that there are no ID's in the backup (so while restoring the db, new ID's will be assigned?)

Strange is that mongo show dbs returns the size of my_db is about 1Gb, but the whole size of .bson files is just 150Mb?

1

There are 1 answers

0
Stennie On

What does it mean: skipping collection: my_db.my_collection.$id, why id field? Does it mean some data wasn't dumped, or that there are no ID's in the backup (so while restoring the db, new ID's will be assigned?)

Collections with a $ are used by system namespaces (in this case the id_ index for your collection) and can safely be skipped. You're only seeing this informational message because you included the -v (verbose) option.

mongodump (2.2+) exports index definitions to a <dbname>.metadata.json file which will be used by mongorestore to recreate indexes when you restore the dump.

Strange is that mongo show dbs returns the size of my_db is about 1Gb, but the whole size of .bson files is just 150Mb?

By default MongoDB preallocates storage to prevent file system fragmentation and reduce delays when new data files need to be created. The allocated file size will be larger than the size of your data. Additionally, MongoDB allocates record padding for documents so that documents have some room to grow in place. The Storage FAQ in the MongoDB manual has more details.

If you run db.stats() for a database you should see both fileSize and dataSize values for comparison. The 150Mb of your BSON files should be close to the dataSize value, while the 1Gb in show dbs will be the fileSize.