
    dhy!                     x    S SK JrJrJrJrJr  S SKJr  S SKJ	r	   " S S\	\
\4   5      r " S S\	\
\4   5      rg)	    )IteratorListOptionalSequenceTuple)Document)	BaseStorec                       \ rS rSrSrSS.S\S\S\S\\   S	S4
S
 jjrS\	\   S	\
\\      4S jrS\	\\\4      S	S4S jrS\	\   S	S4S jrSS\\   S	\\   4S jjrSrg)MongoDBByteStore   aq  BaseStore implementation using MongoDB as the underlying store.

Examples:
    Create a MongoDBByteStore instance and perform operations on it:

    .. code-block:: python

        # Instantiate the MongoDBByteStore with a MongoDB connection
        from langchain.storage import MongoDBByteStore

        mongo_conn_str = "mongodb://localhost:27017/"
        mongodb_store = MongoDBBytesStore(mongo_conn_str, db_name="test-db",
                                     collection_name="test-collection")

        # Set values for keys
        mongodb_store.mset([("key1", "hello"), ("key2", "workd")])

        # Get values for keys
        values = mongodb_store.mget(["key1", "key2"])
        # [bytes1, bytes1]

        # Iterate over keys
        for key in mongodb_store.yield_keys():
            print(key)

        # Delete keys
        mongodb_store.mdelete(["key1", "key2"])
Nclient_kwargsconnection_stringdb_namecollection_namer   returnc                    SSK Jn  U(       d  [        S5      eU(       d  [        S5      eU(       d  [        S5      eU" U40 U=(       d    0 D6U l        U R                  U   U   U l        g! [         a  n[        S5      UeSnAff = fa  Initialize the MongoDBStore with a MongoDB connection string.

Args:
    connection_string (str): MongoDB connection string
    db_name (str): name to use
    collection_name (str): collection name to use
    client_kwargs (dict): Keyword arguments to pass to the Mongo client
r   )MongoClientzRThe MongoDBStore requires the pymongo library to be installed. pip install pymongoNz#connection_string must be provided.zdb_name must be provided.z!collection_name must be provided.pymongor   ImportError
ValueErrorclient
collectionselfr   r   r   r   r   es          [/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/storage/mongodb.py__init__MongoDBByteStore.__init__%        	+ !BCC899@AA#.$
"/"52$
 ++g.?#  	& 		   A- -
B7BBkeysc                     U R                   R                  SSU005      nU Vs0 sH  o3S   US   _M     nnU Vs/ sH  oTR                  U5      PM     sn$ s  snf s  snf )B  Get the list of documents associated with the given keys.

Args:
    keys (list[str]): A list of keys representing Document IDs..

Returns:
    list[Document]: A list of Documents corresponding to the provided
        keys, where each Document is either retrieved successfully or
        represented as None if not found.
_id$invalue)r   findgetr   r$   resultdocresult_dictkeys         r   mgetMongoDBByteStore.mgetJ   se     %%uudm&<=;AB6C5z3w</6B045$55 C5s
   AAkey_value_pairsc                     SSK Jn  U VVs/ sH	  u  p4X4S.PM     nnnU R                  R                  U Vs/ sH  ob" SUS   0SU0SS9PM     sn5        gs  snnf s  snf )	z}Set the given key-value pairs.

Args:
    key_value_pairs (list[tuple[str, Document]]): A list of id-document
        pairs.
r   	UpdateOner'   r)   r'   $setTupsertN)r   r6   r   
bulk_writer   r3   r6   kvupdatesus          r   msetMongoDBByteStore.msetY   sc     	&6EFoda1)oF""MTUWYqx(61+dCWU	
 GUs
   AAc                 B    U R                   R                  SSU005        gz^Delete the given ids.

Args:
    keys (list[str]): A list of keys representing Document IDs..
r'   r(   Nr   delete_manyr   r$   s     r   mdeleteMongoDBByteStore.mdeleteg        	##UUDM$:;    prefixc              #      #    Uc)  U R                   R                  S/S9 H
  nUS   v   M     gU R                   R                  SSSU 300S/S9 H
  nUS   v   M     g7fzNYield keys in the store.

Args:
    prefix (str): prefix of keys to retrieve.
Nr'   )
projectionz$regex^r   r*   r   rL   r.   s      r   
yield_keysMongoDBByteStore.yield_keyso   x      >++w+?%j  @ ++Qvh<01ug ,  %j    AA r   r   N)__name__
__module____qualname____firstlineno____doc__strr   dictr    r   r   bytesr1   r   rA   rH   r   rS   __static_attributes__ rK   r   r   r      s    F )-#@#@ #@ 	#@  ~#@ 
#@J6# 64+@ 6
HU3:->$? 
D 
<HSM <d <!# !(3- ! !rK   r   c                       \ rS rSrSrSS.S\S\S\S\\   S	S4
S
 jjrS\	\   S	\
\\      4S jrS\	\\\4      S	S4S jrS\	\   S	S4S jrSS\\   S	\\   4S jjrSrg)MongoDBStore   a  BaseStore implementation using MongoDB as the underlying store.

Examples:
    Create a MongoDBStore instance and perform operations on it:

    .. code-block:: python

        # Instantiate the MongoDBStore with a MongoDB connection
        from langchain.storage import MongoDBStore

        mongo_conn_str = "mongodb://localhost:27017/"
        mongodb_store = MongoDBStore(mongo_conn_str, db_name="test-db",
                                     collection_name="test-collection")

        # Set values for keys
        doc1 = Document(...)
        doc2 = Document(...)
        mongodb_store.mset([("key1", doc1), ("key2", doc2)])

        # Get values for keys
        values = mongodb_store.mget(["key1", "key2"])
        # [doc1, doc2]

        # Iterate over keys
        for key in mongodb_store.yield_keys():
            print(key)

        # Delete keys
        mongodb_store.mdelete(["key1", "key2"])
Nr   r   r   r   r   r   c                    SSK Jn  U(       d  [        S5      eU(       d  [        S5      eU(       d  [        S5      eU" U40 U=(       d    0 D6U l        U R                  U   U   U l        g! [         a  n[        S5      UeSnAff = fr   r   r   s          r   r    MongoDBStore.__init__   r"   r#   r$   c           
          U R                   R                  SSU005      nU Vs0 sH  o3S   [        S0 US   D6_M     nnU Vs/ sH  oTR                  U5      PM     sn$ s  snf s  snf )r&   r'   r(   r)   rb   )r   r*   r   r+   r,   s         r   r1   MongoDBStore.mget   sm     %%uudm&<=GMNv5z8#;c'l#;;vN045$55 O5s   A A%r3   c                     SSK Jn  U VVs/ sH  u  p4X4R                  S.PM     nnnU R                  R	                  U Vs/ sH  ob" SUS   0SU0SS9PM     sn5        gs  snnf s  snf )	zSet the given key-value pairs.

Args:
    key_value_pairs (list[tuple[str, Document]]): A list of id-document
        pairs.
Returns:
    None
r   r5   r7   r'   r8   Tr9   N)r   r6   __dict__r   r;   r<   s          r   rA   MongoDBStore.mset   sg     	&?NOtq1zz2O""MTUWYqx(61+dCWU	
 PUs   A A&c                 B    U R                   R                  SSU005        grD   rE   rG   s     r   rH   MongoDBStore.mdelete   rJ   rK   rL   c              #      #    Uc)  U R                   R                  S/S9 H
  nUS   v   M     gU R                   R                  SSSU 300S/S9 H
  nUS   v   M     g7frN   rQ   rR   s      r   rS   MongoDBStore.yield_keys   rU   rV   rW   rX   )rY   rZ   r[   r\   r]   r^   r   r_   r    r   r   r   r1   r   rA   rH   r   rS   ra   rb   rK   r   rd   rd      s    J )-#@#@ #@ 	#@  ~#@ 
#@J6# 640B+C 6
HU3=-A$B 
t 
 <HSM <d <!# !(3- ! !rK   rd   N)typingr   r   r   r   r   langchain_core.documentsr   langchain_core.storesr	   r^   r`   r   rd   rb   rK   r   <module>rt      s@    < < - +u!ye, u!py!9S(]+ y!rK   