Summary: Installing the MongoDB community version suitable for M1 chips.
Prerequisites:
- M1 Chip MacBook
- Xcode command line tools installed
- Homebrew installed
Installation Steps#
(It is recommended to have a global scientific internet connection, otherwise there is a high probability of installation failure due to inability to download files properly)
# Download official configuration
brew tap mongodb/brew
# Install MongoDB
brew install mongodb-community@5.0
Installation location:
# Configuration file
/opt/homebrew/etc/mongod.conf
# Log file
/opt/homebrew/var/log/mongodb
# Data directory
/opt/homebrew/var/mongodb
Installation completion log:
==> Summary
🍺 /opt/homebrew/Cellar/mongodb-community/5.0.6: 11 files, 181.5MB, built in 2 seconds
==> Running `brew cleanup mongodb-community`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> mongodb-community
To start mongodb/brew/mongodb-community now and restart at login:
brew services start mongodb/brew/mongodb-community
Or, if you do not want/need a background service you can just run:
mongod --config /opt/homebrew/etc/mongod.conf
Check if the installation is complete:
mongod -version
----
db version v5.0.6
Build Info: {
"version": "5.0.6",
"gitVersion": "212a8dbb47f07427dae194a9c75baec1d81d9259",
"modules": [],
"allocator": "system",
"environment": {
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
Start the service:
# Run as a macOS service
brew services start mongodb-community@5.0
# Stop the service
brew services stop mongodb-community@5.0
# Restart the service
brew services restart mongodb-community@5.0
# View the running services list
brew services list
Basic Usage#
Connect to the database:
mongosh
----
Current Mongosh Log ID: 6232a53ad95c821061c3c2ac
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.3
Using MongoDB: 5.0.6
Using Mongosh: 1.2.3
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
Add a new document:
db.testdb.insertOne({name:"legalgeek",slogen:"hello world"})
{
acknowledged: true,
insertedId: ObjectId("6232a5ced95c821061c3c2ad")
}
Query specific data:
db.testdb.find({name:"legalgeek"})
[
{
_id: ObjectId("6232a5ced95c821061c3c2ad"),
name: 'legalgeek',
slogen: 'hello world'
}
]
Built-in Database Tools#
mongotop
Reference official documentation:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/