문서 홈 → 애플리케이션 개발 → MongoDB 드라이버 → Ruby MongoDB Driver
데이터베이스
이 페이지의 내용
이 버전의 문서는 보관되어 더 이상 지원되지 않습니다.Ruby MongoDB 드라이버 버전을 업그레이드 하는 방법은 최신 문서를 참조하세요.
드라이버는 명령 실행, collection 목록 가져오기, 관리 작업을 위한 데이터베이스 객체에 대한 다양한 도우미를 제공합니다.
listCollections (영문)
collection 또는 데이터베이스의 collection을 가져오려면 collections
및 collection_names
를 각각 사용합니다.
client = Mongo::Client.new([ '127.0.0.1:27017' ], database: 'music') database = client.database database.collections # Returns an array of Collection objects. database.collection_names # Returns an array of collection names as strings.
임의 명령
데이터베이스에서 명령을 실행하려면 command
메서드를 사용하세요.
client = Mongo::Client.new([ '127.0.0.1:27017' ], database: 'music') database = client.database result = database.command(:ping => 1) result.first # Returns the BSON::Document returned from the server.
참고
서버 API 버전을 클라이언트 옵션으로 지정하고 command
메서드에 대한 각 명령 매개변수(즉, apiVersion
, apiStrict
및 apiDeprecationErrors
명령 매개변수)를 동시에 지정하는 것은 허용되지 않으며, 오류가 발생했습니다.
데이터베이스 삭제
데이터베이스를 삭제하려면 drop
메서드를 사용합니다.
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'music') client.database.drop