MirrorNest
← Tous les guides

MongoDB Community Edition

A free, open-source, document-oriented NoSQL database -- installed from MongoDB's own official APT repository (not Ubuntu's default one, which typically lags behind).

Système : Ubuntu 22.04 LTS / 24.04 LTSDatabaseSite officiel ↗Documentation officielle ↗
Ce guide est élaboré à partir de la documentation officielle de MongoDB Community Edition, dont le lien figure ci-dessus — vérifiez toujours les noms exacts des paquets/versions avant d'exécuter ces commandes sur un serveur de production, car les versions de la distribution et du projet évoluent avec le temps.
  1. 1Import MongoDB's official GPG key and repository

    curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb-server-7.0.gpg
    echo "deb [signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

    Check MongoDB's own install docs (linked above) for the current recommended version number -- this changes as new major versions are released.

  2. 2Install it

    sudo apt update
    sudo apt install mongodb-org
  3. 3Start and enable the service

    sudo systemctl start mongod
    sudo systemctl enable mongod
  4. 4Create an admin user

    mongosh
    use admin
    db.createUser({ user: "admin", pwd: "a-real-password", roles: ["root"] })

    MongoDB has no authentication enabled by default -- create this user, then enable `security.authorization: enabled` in /etc/mongod.conf and restart, or anyone who can reach the port has full access.