The mongo Shell

MongoDB Shell 是一个交互式的JavaScript界面,用于查询、更新数据和执行管理任务。文章详细介绍了如何启动并连接到MongoDB实例,包括本地默认和非默认端口、远程主机、认证以及复制集连接,并提供了TLS/SSL连接的方法。此外,还讲解了在Shell中工作的一些基本操作,如格式化输出、多行操作、Tab补全和文件操作。
摘要由CSDN通过智能技术生成

The mongo Shell

On this page

The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mongo shell to query and update data as well as perform administrative operations.

The mongo shell is a component of the MongoDB distributions. Once you have installed and have started MongoDB, connect the mongo shell to your running MongoDB instance.

Start the mongo Shell and Connect to MongoDB

Prerequisites

Ensure that MongoDB is running before attempting to start the mongo shell.

Open a terminal window (or a command prompt for Windows) and go to your <mongodb installationdir>/bin directory:

copy

copied

cd <mongodb installation dir>/bin

TIP

Adding your <mongodb installation dir>/bin to the PATH environment variable allows you to type mongo instead of having to go to the <mongodb installation dir>/bin directory or specify the full path to the binary.

Local MongoDB Instance on Default Port

You can run mongo shell without any command-line options to connect to a MongoDB instance running on your localhost with default port 27017:

copy

copied

mongo

Local MongoDB Instance on a Non-default Port

To explicitly specify the port, include the --port command-line option. For example, to connect to a MongoDB instance running on localhost with a non-default port 28015:

copy

copied

mongo --port 28015

MongoDB Instance on a Remote Host

To explicitly specify the hostname and/or port,

  • You can specify a connection string. For example, to connect to a MongoDB instance running on a remote host machine with default port 27017:

    copy

    copied

    mongo "mongodb://mongodb0.example.com:27017"
    
  • You can use the command-line option <

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值