Native Methods in the Legacy ShellLegacy Shell中的原生方法

The methods listed in this section are for the legacy mongo shell. 本节中列出的方法适用于遗留mongoshell。To use native methods in mongosh, see Native Methods in mongosh.要在mongosh中使用本机方法,请参阅mongosh的原生方法

The mongocompat snippet also provides access to legacy mongo shell APIs.mongocompat片段还提供了对传统mongoshell API的访问。

Note注意

For details on specific methods, including syntax and examples, click on the specific method to go to its reference page.有关特定方法的详细信息,包括语法和示例,请单击特定方法以转到其参考页。

Name名称Description描述
cat()Returns the contents of the specified file.返回指定文件的内容。
cd()Changes the current working directory to the specified path.将当前工作目录更改为指定路径。
copyDbpath()Copies a local dbPath. 复制本地dbPathFor internal use.供内部使用。
getHostName()Returns the hostname of the computer running the shell.返回运行shell的计算机的主机名。
getMemInfo()Returns a document that reports the amount of memory used by the shell.返回一个报告shell使用的内存量的文档。
hostname()Returns the hostname of the system running the shell.返回运行shell的系统的主机名。
isInteractive()Returns a boolean indicating whether the shell is running in interactive or script mode.返回一个布尔值,指示shell是以交互模式还是脚本模式运行。
listFiles()Returns an array of documents that show the name and size of each object in the directory.返回显示目录中每个对象的名称和大小的文档数组。
load()Loads and runs a JavaScript file in the shell.在shell中加载并运行JavaScript文件。
ls()Returns a list of the files in the current directory.返回当前目录中文件的列表。
md5sumFile()The md5 hash of the specified file.指定文件的md5哈希。
mkdir()Creates a directory in the specified path.在指定路径中创建目录。
pwd()Returns the current directory.返回当前目录。
quit()Exits the current shell session.退出当前shell会话。
removeFile()Removes the specified file from the local file system.从本地文件系统中删除指定的文件。
resetDbpath()Removes a local dbPath. 删除本地dbPathFor internal use.供内部使用。
sleep()Suspends mongosh for a period of time.暂停mongosh一段时间。
setVerboseShell()Configures mongosh to report operation timing.配置mongosh以报告操作时间。
version()Returns the current version of mongosh instance.返回mongosh实例的当前版本。
_isWindows()

Returns:退货:

  • true if the shell runs on Windows.如果shell在Windows上运行,则为true
  • false if the shell runs on Unix or Linux.如果shell在Unix或Linux上运行,则为false
_rand()Returns a random number between 0 and 1.返回介于01之间的随机数。
←  Data Types in the Legacy mongo Shellcat() →