Troubleshooting

Errors when retrieving the public key

During Import the public key used by the package management systemstep of the Install MongoDB Community Edition using .deb Packages procedure, you mayencounter a "gpg: no valid OpenPGP data found." error.

Ensure you are copying the command exactly as documented. The operationshould respond with OK.

To check that the MongoDB public GPG key exists on your system,run the following command in the terminal:

  1. sudo apt-key list

The output should include an entry that resembles the following:

  1. /etc/apt/trusted.gpg

pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17] E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6Buid [ unknown] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>

Errors when running sudo apt update

You may encounter one or more errors that resemble the followingwhen running sudo apt-get update as part of theInstall MongoDB Community Edition using .deb Packages procedure:

  1. W: GPG error: https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/4.2 Release: \
  2. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6B
  3. E: The repository 'https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/4.2 Release' \
  4. is not signed.
  5. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
  6. N: See apt-secure(8) manpage for repository creation and user configuration details.

These errors indicate that the MongoDB Public GPG key was notadded in stepImport the public key used by the package management systemof the Install MongoDB Community Edition using .deb Packages procedure.

Repeating theImport the public key used by the package management systemstep of theInstall MongoDB Community Edition using .deb Packages procedure typically resolves thisissue. Ensure you are copying the command and key exactly as documented.

You can validate that the MongoDB public GPG key exists on your systemby running the following command in the terminal:

  1. sudo apt-key list

The output should include an entry that resembles the following:

  1. --------------------
  2. pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17]
  3. E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B
  4. uid [ unknown] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>

Errors when running sudo apt install -y mongodb-org

You may encounter an error that resembles the following when runningsudo apt install -y mongodb-orgin step Create a list file for MongoDB of theInstall MongoDB Community Edition using .deb Packages procedure:

  1. Reading package lists... Done
  2. Building dependency tree
  3. Reading state information... Done
  4. E: Unable to locate package mongodb-org

This error indicates that the/etc/apt/sources.list.d/mongodb-org-4.2.listmay be configured incorrectly or is missing.

To review the contents of the mongodb-org-4.2.list file,run the following command in the terminal or shell:

  1. cat /etc/apt/sources.list.d/mongodb-org-4.2.list

If the file contents do not exactly match the documentation foryour Ubuntu version in the step linked above, remove the file andrepeat the Create a list file for MongoDB step.If the file does not exist, create it as part of that step.

Once you have validated that the mongodb-org-4.2.listfile exists and has the correct contents, runsudo apt update to update the apt repositories andretry sudo apt install -y mongodb-org.

Unable to install package due to dpkg-deb: error

You may encounter an error that resembles the following wheninstalling the mongodb-org package:

  1. dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.2.0_amd64.deb (--unpack):
  2. trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1

This error indicates that the system already had the Ubuntumongodb package installed prior to installing the officialMongoDB Inc. mongodb-org packages. To confirm wheter thehost has the Ubuntu mongodb package installed, run thefollowing command in a terminal or shell:

  1. sudo apt list --installed | grep mongo

If your output resembles the following, you must uninstallthe Ubuntu mongodb package before retrying theInstall MongoDB Community Edition using .deb Packages procedure:

  1. mongodb/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed]
  2. mongodb-clients/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic]
  3. mongodb-server/bionic,bionic,now 1:3.6.3-0ubuntu1 all [installed,automatic]
  4. mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic]

Run the following commands in a terminal or shell to fully remove theUbuntu mongodb package before retrying the installationprocedure:

  1. sudo apt remove mongodb
  2. sudo apt purge mongodb
  3. sudo apt autoremove

Note

sudo apt purge mongodb removes any default configuration filesinstalled by the Ubuntu mongodb package. If you havemodified these configuration files and want to keep thosemodifications, copy the files to another directory such as/home/your-user-name.

If your output includes a mix of mongodb-org andmongodb binaries, you may need to first apt remove, aptpurge, and apt autoremove the mongodb-org packagebefore attempting to remove and purge the Ubuntu mongodbpackage. After clearing all MongoDB-related packages, retry theinstallation procedure.

You may encounter the Socket is already in use orFailed to unlink socket file errors when starting amongod. These errors generally indicateanother process using the configured port for themongod process, typically anothermongod running on the system.

The following example uses the ss utility to list all openTCP (-t) or UDP (-u) sockets in the LISTEN (-l) stateand the process using each socket (-p)without resolving any service names or hostnames (-n).

  1. sudo ss --tulpn

The following partial output shows a mongod processlistening on the 27017 port. Attempting to run another mongodprocess on that same port will result in socket errors.

  1. Netid State Local Address:Port
  2. udp UNCONN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=12))
  3. udp UNCONN 10.1.16.87%enp0s3:68 users:(("systemd-network",pid=652,fd=15))
  4. tcp LISTEN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=13))
  5. tcp LISTEN 0.0.0.0:22 users:(("sshd",pid=819,fd=3))
  6. tcp LISTEN 192.168.1.15:27017 users:(("mongod",pid=10027,fd=12))
  7. tcp LISTEN 127.0.0.1:27017 users:(("mongod",pid=10027,fd=11))
  8. tcp LISTEN ::]:22 users:(("sshd",pid=819,fd=4))

If the system has a mongod or other systemprocess running on your desired port, you must either shut theexisting process down or select a new port for the newmongod process. You can specify thenet.portconfiguration fileoption to change the port that the mongodlistens on.

Users may encounter errors that resemble the following in themongodprocess log:

  1. Data directory ... not found
  2.  
  3. Attempted to create lock file on a read-only directory: ...

The mongod uses the directory specified to thestorage.dbPath configuration file setting or the—dbpath command line option for storing itsdata files. The directory permission and ownership settings must allowthe mongod to read, write, and navigate thedirectory contents (rwx user or group permissions).

The mongod process does not automatically createits data directory nor can it modify permissions or ownership to gainaccess to the directory. Use utilities like mkdir, chown, andchmod to create directories, modify permissions, and setuser:group ownership as appropriate prior to starting themongod.

Users starting the mongod as a service(e.g. sudo service mongod start) typically only see these errorsif they modified the default dbPath value inthe /etc/mongod.conf to:

  • A directory that does not allow the mongodb user or mongodbgroup to read, write, or execute (rwx) the directory and itscontents, or
  • A directory that does not exist.

Users starting the mongod without using theservice definition (e.g. using the terminal to launch mongod)typically see these errors if:

  • The directory specified to dbPath or—dbpath does not allow the user or agroup to which the user belongs to read, write, and execute(rwx) the directory or its contents, or
  • The specified data directory does not exist.