Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

isInteractive()

On this page

  • Examples

Note

isInteractive()

New in version 4.2.

Returns a boolean value indicating if the current mongosh session is running in interactive mode or in script mode:

  • true if in interactive mode

  • false if in script mode

Connect mongosh to a deployment. Inside mongosh, run:

isInteractive()

The method returns true.

Create a JavaScript testExample.js file with the content:

print("Is the shell in interactive mode? " + isInteractive() );

Connect mongosh to a deployment. Inside mongosh, load the javascript file (see load()):

let loadStatus = load("testExample.js"); //You may need to specify the path to the file

The method returns the following in mongosh:

Is the shell in interactive mode? true

Create a JavaScript testExample.js file with the content:

print("\n\nIs the shell in interactive mode? " + isInteractive() );

From a terminal/command-line prompt (i.e. not inside mongosh), specify the javascript file to mongosh in order to execute the file, as follows:

mongosh localhost:27017/test testExample.js

The operation prints to the terminal information about the MongoDB shell version and various information followed by:

MongoDB shell version v4.4.0
...
Is the shell in interactive mode? false
←  hostname()listFiles() →

On this page