AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.

스키마 예제

이 가이드에서는 일반적인 상황에서 PyMongoArrow 스키마를 사용하는 방법의 예를 보여줍니다.

애그리게이션 또는 찾기 작업을 수행할 때 struct 객체를 사용하여 중첩된 데이터에 대한 스키마를 제공할 수 있습니다. 상위 문서와 비교하여 하위 문서에 이름이 충돌할 수 있습니다.

>>> from pymongo import MongoClient... from pymongoarrow.api import Schema, find_arrow_all... from pyarrow import struct, field, int32... coll = MongoClient().db.coll... coll.insert_many(... [... {"start": "string", "prop": {"name": "foo", "start": 0}},... {"start": "string", "prop": {"name": "bar", "start": 10}},... ]... )... arrow_table = find_arrow_all(... coll, {}, schema=Schema({"start": str, "prop": struct([field("start", int32())])})... )... print(arrow_table)pyarrow.Tablestart: stringprop: struct<start: int32> child 0, start: int32----start: [["string","string"]]prop: [ -- is_valid: all not null -- child 0 type: int32[0,10]]

Pandas와 NumPy를 사용할 때도 동일한 작업을 수행할 수 있습니다.

>>> df = find_pandas_all(... coll, {}, schema=Schema({"start": str, "prop": struct([field("start", int32())])})... )... print(df) start prop0 string {'start': 0}1 string {'start': 10}

데이터를 PyMongoArrow로 전달하기 전에 프로젝션을 사용하여 데이터를 평면화할 수도 있습니다. 다음 예는 매우 간단한 중첩 문서 구조를 사용하여 이 작업을 수행하는 방법을 보여줍니다.

>>> df = find_pandas_all(... coll,... {... "prop.start": {... "$gte": 0,... "$lte": 10,... }... },... projection={"propName": "$prop.name", "propStart": "$prop.start"},... schema=Schema({"_id": ObjectIdType(), "propStart": int, "propName": str}),... )... print(df) _id propStart propName0 b'c\xec2\x98R(\xc9\x1e@#\xcc\xbb' 0 foo1 b'c\xec2\x98R(\xc9\x1e@#\xcc\xbc' 10 bar

애그리게이션 작업을 수행할 때 다음 예와 같이 $project 단계를 사용하여 필드를 평면화할 수 있습니다.

>>> df = aggregate_pandas_all(... coll,... pipeline=[... {"$match": {"prop.start": {"$gte": 0, "$lte": 10}}},... {... "$project": {... "propStart": "$prop.start",... "propName": "$prop.name",... }... },... ],... )