문서 메뉴
문서 홈
/
MongoDB 매뉴얼
/ / /

isInteractive()

이 페이지의 내용

  • 예제

참고

여기에 나열된 네이티브 메서드는 레거시 mongo 셸에 사용됩니다.

mongosh 에서 네이티브 메서드를 사용하려면 mongosh 의 네이티브 메서드를 참조하세요.

isInteractive()

버전 4.2에 추가되었습니다.

현재 mongosh 세션이 대화형 모드에서 실행 중인지 스크립트 모드에서 실행 중인지 나타내는 부울 값을 반환합니다.

  • true 대화형 모드인 경우

  • false 스크립트 모드에 있는 경우

mongosh 를 배포서버에 연결합니다. mongosh 내에서 다음을 실행합니다.

isInteractive()

이 메서드는 true 을(를) 반환합니다.

콘텐츠가 포함된 JavaScript testExample.js 파일을 만듭니다.

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

mongosh 를 배포서버에 연결합니다. mongosh 내에서 JavaScript 파일을 로드합니다( load() 참조).

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

이 메서드는 mongosh에서 다음을 반환합니다.

Is the shell in interactive mode? true

콘텐츠가 포함된 JavaScript testExample.js 파일을 만듭니다.

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

터미널/명령줄 프롬프트(즉, mongosh 내부가 아님)에서 파일을 실행하려면 다음과 같이 JavaScript 파일을 mongosh 로 지정합니다.

mongosh localhost:27017/test testExample.js

이 작업은 MongoDB Shell 버전에 대한 정보와 다양한 정보를 터미널에 출력한 후 다음과 같이 출력합니다.

MongoDB shell version v4.4.0
...
Is the shell in interactive mode? false

돌아가기

hostname()

다음

listFiles()

이 페이지의 내용