• 회원가입
  • 로그인
  • 구글아이디로 로그인

[mongodb] Python - MongoDB Create Collection (컬렉션 생성)

1711  

목차

  1. collection 생성
  2. collection 존재 체크

 

collection 생성

※ hz이라는 DB에 hz_member라는 컬렉션 생성.

 

import pymongo


myclient = pymongo.MongoClient('mongodb://localhost:27017/')

mydb = myclient['hz']

mycol = mydb["hz_member"]

 

※ 에러 없으면 정상적으로 생성된 것임.

※ 주의: MongoDB는 콘텐츠 가져올 때까지 Collection 생성 안 함.

※ 최초로 Collection 생성 시, 먼저 데이터를 넣어야 존재 체크 가능.

 

collection 존재 체크

[모든 collection 확인]

※ hz_level, hz_member 컬렉션 생성 후, 존재 확인.

 

import pymongo


myclient = pymongo.MongoClient('mongodb://localhost:27017/')

mydb = myclient['hz']

mycol = mydb["hz_member"]

mycol = mydb["hz_level"]

print(mydb.list_collection_names())

 

결과값: ['hz_level', 'hz_member']


[특정 collection 확인]

 

import pymongo


myclient = pymongo.MongoClient('mongodb://localhost:27017/')

mydb = myclient['hz']

mycol = mydb["hz_member"]

mycol = mydb["hz_level"]

collist = mydb.list_collection_names()

if "hz_member" in collist:

  print("hz_member 컬렉션 존재 O")

 

결과값: hz_member 컬렉션 존재 O 



분류 제목
module Python - random.normalvariate() 메서드 △ - 정규분포 (확률이론용) 기반 랜덤 …
module Python - random.vonmisesvariate() 메서드 △ - 폰미제스분포 (방향통계) 기반 랜…
module Python - random.paretovariate() 메서드 △ - 파레토분포 (확률이론) 기반 랜덤 부…
module Python - random.weibullvariate() 메서드 △ - 베이블분포 (통계) 기반 랜덤 부동…
module Python - requests 모듈 메서드 종류 (※ 요청 모듈)
module Python - requests.delete() 메서드 - 지정 URL에 DELETE 요청 보냄. (= de…
module Python - requests.get() 메서드 - 지정 URL에 GET 요청 보냄. (= get메서드 =…
module Python - requests.head() 메서드 - 지정 URL에 HEAD 요청 보냄. (= head메서…
module Python - requests.patch() 메서드 △ - 지정 URL에 PATCH 요청 보냄. (= pa…
module Python - requests.post() 메서드 -
module Python - requests.put() 메서드 △ - 지정 URL에 PUT 요청 보냄. (= put메서드…
module Python - requests.request() 메서드 △ - 지정 메서드의 요청을 지정 URL로 보냄. …
function Python - abs() 함수 ★ - 숫자의 절대값 반환. (= abs함수 = 앱스함수/에이비에스함수/앱솔…
function Python - all() 함수 - 반복 가능 객체의 요소가 모두 True인지 체크. (= all함수 = 올…
function Python - any() 함수 - 반복 가능 객체의 요소가 하나라도 True인지 체크. (= any함수 =…
function Python - ascii() 함수 - 객체의 읽기 가능 버전 반환. (= ascii함수 = 아스키함수)
function Python - bin() 함수 - 정수의 이진수 값 반환. (= bin함수 = 빈함수/바이너리함수)
function Python - bool() 함수 ★ - 객체의 참거짓 반환. (= 참인지 거짓인지 판별 = bool함수 =…
function Python - bytearray() 함수 - 바이트 배열 생성. (= bytearray함수 = 바이트어레이…
function Python - bytes() 함수 - 바이트 객체 반환. (= bytes함수= 바이츠함수)
5/24
목록
찾아주셔서 감사합니다. Since 2012