Docs Home → Develop Applications → MongoDB Manual
Native Methods in mongosh
The methods listed in this section are mongosh
functional
replacements for the native methods that were
available in the legacy mongo
shell. These methods are not
exact replacements: output formats and some functionality may differ
from the corresponding legacy methods.
In addition to these methods, the mongocompat snippet
provides access to legacy mongo
shell APIs.
Note
In the following table <path>
and <filename>
are strings and
should be in quotes.
// process.chdir( <path> ) process.chdir( "./data/incoming" )
Legacy Method Name | Replacement | ||
---|---|---|---|
cat() | Returns the contents of the specified file
The legacy useBinaryMode option is
not supported. Emulate the
| ||
cd() | Changes the current working directory to the specified path.
| ||
getHostName() | Returns the hostname of the system running
| ||
getMemInfo() | Returns a document that reports memory used by the shell.
| ||
hostname() | Returns the hostname of the computer running the shell.
| ||
isInteractive() | Returns a boolean indicating whether
| ||
listFiles() | Returns an array of documents that give the name and type of each object in the directory.
| ||
load() | Loads and runs a JavaScript file in the shell.
| ||
ls() | Returns a list of the files in the current directory.
| ||
md5sumFile() | Returns the md5 hash of the specified file.
| ||
mkdir() | Creates a directory at the specified path.
| ||
pwd() | Returns the current directory.
| ||
quit() | Exits the current shell session.
| ||
removeFile() | Removes the specified file from the local file system.
| ||
sleep() | Sleep for the specified number of milliseconds.
| ||
version() | Returns the current version of
| ||
_isWindows() | Returns
| ||
Returns a random number between
|