Collection

이 문서는 DocumentDB의 데이터 집합인 컬렉션 관리 방법에 대해서 설명합니다.

생성

컬렉션은 다음과 같이 DocumentDB.create_collection 함수를 통해 생성할 수 있습니다. 인자는 컬렉션의 이름과 컬렉션에서 사용할 색인에 대한 스키마가 전달됩니다.

from aeca import DocumentDB
 
doc_db = DocumentDB(channel)
 
indexes = [
    {
        "index_type": "kPrimaryKey",
        "fields": ["doc_id"]
    }
]
collection_name = "first_collection"
doc_db.create_collection(collection_name, indexes=indexes)

인덱스를 위한 스키마 정의

색인을 위한 스키마 정의 방법은 색인을 위한 스키마에서 확인할 수 있습니다.

조회

저장된 colleciton을 조회하는 방법을 설명합니다. DocumentDB.list_collections 함수를 통해 전체 colleciton 목록을 확인할 수 있습니다.

doc_db.list_collections()
실행 결과
['first_collection']

DocumentDB.get_collection 함수를 통해 colleciton의 색인 정보와 통계값을 확인할 수 있습니다.

doc_db.get_collection(collection_name)
실행 결과
{'success': True,
 'message': 'OK',
 'profile': {'duration': {'query': 0, 'serialization': 0, 'unit': 'us'}},
 'data': [{'collection_name': 'first_collection',
   'indexes': [{'index_id': 1,
     'index_name': '__primary_key__',
     'fields': ['doc_id'],
     'unique': True,
     'index_type': 'kPrimaryKey',
     'status': 'kEnabled',
     'options': {}}],
   'statistics': [{'index_id': 1,
     'index_name': '__primary_key__',
     'approximated_size': 0,
     'num_docs': 0,
     'accessed': 0,
     'added': 0,
     'updated': 0,
     'deleted': 0,
     'merged': 0,
     'accessed_at': 0,
     'added_at': 0,
     'updated_at': 0,
     'deleted_at': 0,
     'merged_at': 0}]}]}

편집

DocumentDB.rename_collection 함수를 통해 컬렉션의 이름을 수정할 수 있습니다.

doc_db.rename_collection(collection_name, "second_collection")

삭제

DocumentDB.drop_collection 함수를 통해 삭제할 수 있습니다.

doc_db.drop_collection(collection_name)