Docs Menu
Docs Home
/
MongoDB Manual
/ / /

isInteractive()

On this page

  • Examples
isInteractive()

New in version 4.2.

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

  • true if in interactive mode

  • false if in script mode

Connect a mongo shell to a deployment. Inside the mongo shell, type:

isInteractive()

The method returns true.

Create a JavaScript testExample.js file with the content:

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

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

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

The method returns in the mongo shell:

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 the mongo shell), specify the javascript file to the mongo shell to execute the file:

mongo 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.2.0
...
Is the shell in interactive mode? false

Back

hostname()

On this page