3

I have really been puzzled by this one. Below is my database and collections. I can not get mongoexport to dump the collection itunes_itunes_level4_US_uniq into json.

I'm trying this via:

mongoexport  -d test-database -c itunes_itunes_level4_US_uniq -o itunes_itunes_level4_US_uniq.json

2016-07-21T19:09:37.507-0500 connected to: localhost 2016-07-21T19:09:37.508-0500 exported 0 records

Same command allows me to export the other collections successfully. What am I doing wrong?

> show dbs
admin           (empty)
local           0.078GB
test            0.078GB
test-database  47.931GB

> show collections
[object Object]
extract
extract_4l
extract_level4
itunes_itunes_level4_US_uniq
itunes_level4_US
rabbit_US_uniq
system.indexes

> use test-database
switched to db test-database

> db.itunes_itunes_level4_US_uniq.stats(1024)
{
    "ns" : "test-database.itunes_itunes_level4_US_uniq",
    "count" : 986099,
    "size" : 5295580,
    "avgObjSize" : 5499,
    "storageSize" : 6002404,
    "numExtents" : 24,
    "nindexes" : 1,
    "lastExtentSize" : 1818052,
    "paddingFactor" : 1,
    "systemFlags" : 1,
    "userFlags" : 1,
    "totalIndexSize" : 7,
    "indexSizes" : {
        "_id_" : 7
    },
    "ok" : 1
} 
5
  • Your command line looks correct. Are you certain you're connected to the correct server? Is it possible that you may be missing a --port or --host option?
    – kevinadi
    Jul 22, 2016 at 5:01
  • I'm certain that I'm connected to the right server - port etc. It's my local machine, and it has only one database with data. I'm able to send out the other collections in the list to json. Is it possible that some collections are not exportable? The particular collection is generated as a result of a aggregation... shouldn't matter but...
    – thasainta
    Jul 23, 2016 at 13:50
  • All collections should be exportable. The only way I could replicate your situation is if either the collection doesn't exist, or the collection contains no data. What is your MongoDB version, and could you also check if the mongod process, the mongo shell, and the mongoexport tool are all the same version?
    – kevinadi
    Jul 25, 2016 at 0:31
  • Collection definitely exist and is in the only populated DB as you can see from the initial output - something weird is going on. Here are the versions:mongo MongoDB shell version: 3.2.6 > db.version() 2.6.10 mongoexport --version mongoexport version: r3.2.6 git version: 6dab8f99eaafb764443531dc528d4b4b76eb57f2 mongod --version db version v3.2.6 git version: 05552b562c7a0b3143a729aaa0838e558dc49b25 OpenSSL version: OpenSSL 1.0.2g-fips 1 Mar 2016 allocator: tcmalloc modules: none build environment: distmod: ubuntu1404 distarch: x86_64 target_arch: x86_64
    – thasainta
    Jul 25, 2016 at 3:35
  • Definitely strange. I tried using the versions you are using, aggregated out a collection, and mongoexport the aggregation result, and got the data out. Maybe it's worth it to try exporting a different collection and see if it's a problem with this particular collection? Also you could try if mongodump can dump the collection?
    – kevinadi
    Jul 25, 2016 at 5:36

1 Answer 1

0
mongoexport --db test-database --collection itunes_itunes_level4_US_uniq --out itunes_itunes_level4_US_uniq.json

Export whole db and find your collection in it by following command :

mongodump -d <database name> -o <directory_backup>

use above command.

1
  • Appreciate the suggestion to dump the db, but that is not particularly elegant way to get one relatively small collection out of a large db... wished the failing export was providing a bit more info.
    – thasainta
    Jul 23, 2016 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.