mongodb入门(一)

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 the directConnection=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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值