参考 > 参考 > mongo Shell方法 > Native Methods > isInteractive()
在本页面
isInteractive
4.2版中的新功能。
返回一个布尔值,该值指示当前 mongoshell是在交互模式下还是在脚本模式下运行:
mongo
true
false
将mongo外壳连接到部署。在 mongo外壳内,键入:
isInteractive()
方法返回true。
创建一个testExample.js包含以下内容的JavaScript 文件:
testExample.js
print("Is the shell in interactive mode? " + isInteractive() );
将mongo外壳连接到部署。在 mongo外壳内,加载javascript文件(请参阅参考资料 load()):
load()
let loadStatus = load("testExample.js"); //You may need to specify the path to the file
该方法在mongo外壳中返回:
Is the shell in interactive mode? true
print("\n\nIs the shell in interactive mode? " + isInteractive() );
在终端/命令行提示符下(即不在 mongoshell内),将JavaScript文件指定给 mongoshell以执行该文件:
mongo localhost:27017/test testExample.js
该操作将有关MongoDB Shell版本的信息和各种信息打印到终端,其后是:
MongoDB shell version v4.2.0 ... Is the shell in interactive mode? false