mkdir()

Description

  • mkdir(path)
  • Creates a directory at the specified path. This method createsthe entire path specified if the enclosing directory ordirectories do not already exit. The user running themongo shell must have permission to create directories inthe specified path.

This method is equivalent to mkdir -p with BSD or GNU utilities.

The mkdir() method has the following parameter:

ParameterTypeDescriptionpathstringA path on the local filesystem.

New in version 3.4.

mkdir() returns a document withinformation about the result of the operation.

On success, mkdir() returns the following:

  1. { "exists" : true, "created" : true }

If the directory at the specified path already exists,mkdir() returns the following:

  1. { "exists" : true, "created" : false }

Example

The following command creates a directory called foo in theshell’s current working directory.

  1. mkdir("foo")

The above command returns the following output:

  1. { "exists" : true, "created" : true }