isInteractive()
이 페이지의 내용
MongoDB 5.0 은(는) 2024 10월을 기준으로 수명이 종료됩니다. 이 버전의 문서는 더 이상 지원되지 않습니다. 5.0 배포서버 업그레이드 하려면 MongoDB.6 0 업그레이드 절차를 참조하세요.
참고
여기에 나열된 네이티브 메서드는 레거시 mongo
shell 입니다.
에서 네이티브 메서드를 사용하려면 의 mongosh
네이티브 메서드를 mongosh
참조하세요.
isInteractive()
버전 4.2에 추가되었습니다.
현재
mongosh
세션이 대화형 모드에서 실행 중인지 스크립트 모드에서 실행 중인지 나타내는 부울 값을 반환합니다.true
대화형 모드인 경우false
스크립트 모드에 있는 경우
예시
인터랙티브 모드
shell 내부에서 작업 실행
mongosh
를 배포서버에 연결합니다. mongosh
내에서 다음을 실행합니다.
isInteractive()
이 메서드는 true
을(를) 반환합니다.
내부에서 Javascript 파일 실행 mongosh
콘텐츠가 포함된 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