MongoDB Export/Import Failed: error counting I am trying to export data from local database using:

mongodump --db ride4you --collection rides


But I receive the next error: 

Failed: error counting ride4you.rides: not authorized on ride4you to execute command { count: "rides", query: {} }


What is this and what to do?
Plus, is there a way to export the whole database at once, instead by each table?
@Raz, I have gone through your mongodump statement. You are doing mistake.


  mongodump --db ride4you --collection rides


As per your mongodump code , As i am able to understand in your mongodump code, there is database name (ride4you) and collection name (rides) without the path of dump (.JSON) file.

Let's start from beginning. As per MongoDB BOL , if you are in BIN directory . Just type along with mongodump --help. You shall get the mongodump command all details. Which i am copy and paste from my environment.

C:\Program Files\MongoDB\Server\3.2\bin&gt;mongodump --help
Usage:
  mongodump &lt;options&gt;

Export the content of a running server into .bson files.

Specify a database with -d and a collection with -c to only dump that database or

See http://docs.mongodb.org/manual/reference/program/mongodump/ for more informat

general options:
      /help                                                 print usage
      /version                                              print the tool
                                                            version and exit

verbosity options:
  /v, /verbose:&lt;level&gt;                                      more detailed log
                                                            output (include
                                                            multiple times for
                                                            more verbosity,
                                                            e.g. -vvvvv, or
                                                            specify a numeric
                                                            value, e.g.
                                                            --verbose=N)
      /quiet                                                hide all log output

connection options:
  /h, /host:&lt;hostname&gt;                                      mongodb host to
                                                            connect to
                                                            (setname/host1,host-

                                                            2 for replica sets)
      /port:&lt;port&gt;                                          server port (can
                                                            also use --host
                                                            hostname:port)

authentication options:
  /u, /username:&lt;username&gt;                                  username for
                                                            authentication
  /p, /password:&lt;password&gt;                                  password for
                                                            authentication
      /authenticationDatabase:&lt;database-name&gt;               database that holds
                                                            the user's
                                                            credentials
      /authenticationMechanism:&lt;mechanism&gt;                  authentication
                                                            mechanism to use

namespace options:
  /d, /db:&lt;database-name&gt;                                   database to use
  /c, /collection:&lt;collection-name&gt;                         collection to use

query options:
  /q, /query:                                               query filter, as a
                                                            JSON string, e.g.,
                                                            '{x:{$gt:1}}'
      /queryFile:                                           path to a file
                                                            containing a query
                                                            filter (JSON)
      /readPreference:&lt;string&gt;|&lt;json&gt;                       specify either a
                                                            preference name or
                                                            a preference json
                                                            object
      /forceTableScan                                       force a table scan

output options:
  /o, /out:&lt;directory-path&gt;                                 output directory,
                                                            or '-' for stdout
                                                            (defaults to 'dump')
      /gzip                                                 compress archive
                                                            our collection
                                                            output with Gzip
      /repair                                               try to recover
                                                            documents from
                                                            damaged data files
                                                            (not supported by
                                                            all storage engines)
      /oplog                                                use oplog for
                                                            taking a
                                                            point-in-time
                                                            snapshot
      /archive:&lt;file-path&gt;                                  dump as an archive
                                                            to the specified
                                                            path. If flag is
                                                            specified without a
                                                            value, archive is
                                                            written to stdout
      /dumpDbUsersAndRoles                                  dump user and role
                                                            definitions for the
                                                            specified database
      /excludeCollection:&lt;collection-name&gt;                  collection to
                                                            exclude from the
                                                            dump (may be
                                                            specified multiple
                                                            times to exclude
                                                            additional
                                                            collections)
      /excludeCollectionsWithPrefix:&lt;collection-prefix&gt;     exclude all
                                                            collections from
                                                            the dump that have
                                                            the given prefix
                                                            (may be specified
                                                            multiple times to
                                                            exclude additional
                                                            prefixes)
  /j, /numParallelCollections:                              number of
                                                            collections to dump
                                                            in parallel (4 by
                                                            default)


Mostly i am doing mongodump in my environment like 

For a single database dump 

mongodump -d myfirstdb -o C:\Test\TestDB.json


For all database dump at a time

mongodump --verbose C:\Test\


Here In first statement myfirstdb is database in my MongoDB Server. -o is for output directory options and C:\Test  is a folder where TestDB.json my dump (.JSON) File reside.

In second statement i have used --verbose . for more details output

Note: mongodump import all dump (.JSON) files in MongoDB Server at a time. But when doing mongoimport then it import one dump (.JSON) file at a time.

For Further your ref mongodump