Mongoexport returns Exported 0 Records

Hi, first time posting here. I searched for my issue but only found results from over a year ago. I have a digital ocean mongo server, I am connected to it and from shell trying to export.

This all seems pretty straightforward and feel I must be missing something very generic/obvious.

I am running MongoDB 4.0.3 on Ubuntu 18.04, and mongoexport returns same version r4.0.3

mongoexport --collection test --db resolutions --authenticationDatabase admin --username myadminusername --password myStr0ngPassw0rd

  • if I change the username or password to invalids, returns authentication failed.
  • if I change the collection or database to invalids, I get the same as when correct values.

I have a resolutions database in a test collection, simple naming with no special characters. I am logged in as super user.

connected to: localhost
exported 0 records

Help? Thanks in advance!

Welcome to the MongoDB Community Forums @Richie_Madden !

Your usage looks fine so I expect there is an issue with the namespace parameters or the target deployment.

A database contains one or more collections. I’m wondering if perhaps you have a resolutions collection in a test database, which would mean your --collection and --db parameter values need to be swapped.

f you want to double-check the database and collection names in the mongo shell, the following count should match the count of documents exported by your original mongoexport command line:

db.getSiblingDB(‘resolutions’).getCollection(‘test’).count()

That is expected behaviour: if a namespace is empty or doesn’t exist, there will 0 documents exported.

Are you running mongoexport in the same Digital Ocean instance as your MongoDB deployment or using port forwarding? If not, localhost may not be connecting to the intended deployment.

Regards,
Stennie

THANK YOU THANK YOU THANK YOU

Stupid user error. Yep, had db and collection reversed. I have been working with RDBMS systems for decades and I am still new to document databases, MongoDB. I have still not fully translated collection to table, IMO. With that, with collection being a new word in my head, I mixed them up.

Humbling! Needed this I guess to never do it again.

Immediately my local export on Windows 10 using Putty for tunnel for connection worked and exported all records as needed.

Thank you Stennie! So much appreciated.

1 Like

Hi @Richie_Madden,

Glad that worked out! No need to apologise for being a learner – we all have to pass through that stage :wink:

If you prefer GUI to command line, you may be interested in MongoDB Compass which includes a more visual way to confirm you are exporting the expected data: Export Data from a Collection.

Regards,
Stennie

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.