문서 메뉴

문서 홈애플리케이션 개발MongoDB 드라이버Ruby MongoDB Driver

데이터베이스

이 페이지의 내용

  • listCollections (영문)
  • 임의 명령
  • 데이터베이스 삭제

드라이버는 명령 실행, collection 목록 가져오기, 관리 작업을 위한 데이터베이스 객체에 대한 다양한 도우미를 제공합니다.

collection 또는 데이터베이스의 collection을 가져오려면 collectionscollection_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, apiStrictapiDeprecationErrors 명령 매개변수)를 동시에 지정하는 것은 허용되지 않으며, 오류가 발생했습니다.

데이터베이스를 삭제하려면 drop 메서드를 사용합니다.

client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'music')
client.database.drop
←  스키마 작업컬렉션 →