You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MongoDB Shell中输入JavaScript代码时如何换行(显示...)?

How to Write Multi-Line JavaScript with Ellipsis "..." in MongoDB Shell

Hey there! Great question—this behavior you're seeing is a native feature of the MongoDB shell (both the modern mongosh and the legacy mongo shell) designed to make writing multi-line JavaScript code smoother. Here's how it works and how you can replicate it:

Automatic Multi-Line Mode

The shell will automatically switch to multi-line mode (showing the ... prompt) when it detects that your code is incomplete. Common scenarios include:

  • Opening a curly brace { or parenthesis ( without closing it
  • Starting a function definition, if statement, or loop that requires additional lines
  • Leaving a statement unfinished (like a variable assignment without a value)

For example, if you type this and hit Enter:

db.users.find({

The shell will immediately show ... and wait for you to continue writing your query, like:

... name: "Alice",
... age: { $gt: 30 }
... })

Hit Enter one more time after closing the brace/parenthesis, and the shell will execute the full command.

Manual Multi-Line Mode

If you want to start a multi-line block even with complete syntax (like splitting a long query for readability), you can use keyboard shortcuts to trigger it:

  • On Windows/Linux: Press Ctrl + Enter instead of just Enter
  • On Mac: Press Cmd + Enter instead of just Enter

This will bring up the ... prompt, letting you type each line of code on a new line before executing the whole block.

Useful Tips

  • To exit multi-line mode without running your code, press Ctrl + C
  • Use arrow keys or shortcuts like Ctrl + P (previous line) / Ctrl + N (next line) to navigate and edit lines in multi-line mode
  • Once you finish writing your full code block, press Enter one last time to execute it

内容的提问来源于stack exchange,提问作者mrwadepro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:18:52