MongoDB安装
mac安装,tgz方式
mac安装,tgz方式(Install MongoDB Community on macOS using .tgz Tarball)
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/
软件下载
https://www.mongodb.com/try/download/community
mac安装, brew方式
brew tap mongodb/brew
brew install mongodb-community@5.0
启动
brew services start mongodb-community@5.0
查看
brew services list
基本操作
Connect and Use MongoDB
To begin using MongoDB, connect
mongosh
to the running instance. From a new terminal, issue the following:mongosh 链接 Remote Host¶
mongosh "mongodb://mongodb0.example.com:28015"
Connect to a Replica Set¶
mongosh
adds thedirectConnection=true
query parameter to the connection string automatically unless at least one of the following is true:
- The
replicaSet
query parameter is present in the connection string.
- The connection string uses the
mongodb+srv://
scheme.
- The connection string contains a seed list with multiple hosts.
Using the MongoDB Database Tools
mongodump,mongoimport
reporting usage statistics
mongotop
MongoDB Shell
MongoDB Shell mongosh 是一个功能齐全的 JavaScript 和 Node.js 14.x REPL 环境,用于与 MongoDB 部署进行交互。 您可以使用 MongoDB Shell 直接对数据库测试查询和操作。
Insert Document
要插入单个文档,请使用 db.collection.insertOne()。
要插入多个文档,请使用 db.collection.insertMany()。
Update Documents
To update a single document, use
db.collection.updateOne()
.
To update multiple documents, use
db.collection.updateMany()
.
To replace a document, use
db.collection.replaceOne()
.
Delete Documents
Run Aggregation Pipelines
Write Scripts for mongosh
printjson(db.adminCommand('listDatabases'))
mongosh -f 1.js
参考文档
操作手册
https://docs.mongodb.com/manual/