As of today(Aug 29 2023) a binary for Debian 12 is not available yet. Although we can use Ubuntu's repo to install MongoDB on Debian 12.
Prerequisites:
sudo apt-get install gnupg curl
Import the GPG key for the repo:
curl -fsSL https://pgp.mongodb.com/server-7.0.asc |sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/mongodb-server-7.0.gpg
Adding the repository to the source list:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Reload the local package database:
sudo apt-get update
Install the latest stable version of MongoDB:
sudo apt-get install -y mongodb-org
Start mongod service:
sudo systemctl start mongod
Verify:
sudo systemctl status mongod
Start MongoDB on system startup (optional):
sudo systemctl enable mongod
Run mongo by using the following command:
mongosh