Docs Menu

mkdir()

On this page

  • Description
  • Example
Note

The native method listed here is for the legacy mongo shell.

To use native methods in mongosh, see Native Methods in mongosh.

mkdir(path)

Creates a directory at the specified path. This method creates the entire path specified if the enclosing directory or directories do not already exit. The user running mongosh must have permission to create directories in the specified path.

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

The mkdir() method has the following parameter:

Parameter
Type
Description
path
string
A path on the local filesystem.

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

On success, mkdir() returns the following:

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

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

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

The following command creates a directory called foo in the shell's current working directory.

mkdir("foo")

The above command returns the following output:

{ "exists" : true, "created" : true }
←  md5sumFile()pwd() →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.