mirror of
https://github.com/Unstructured-IO/unstructured.git
synced 2025-08-10 17:59:09 +00:00

### Description This adds the basic implementation of pushing the generated json output of partition to mongodb. None of this code provisions the mondo db instance so things like adding a search index around the embedding content must be done by the user. Any sort of schema validation would also have to take place via user-specific configuration on the database. This update makes no assumptions about the configuration of the database itself.
69 lines
2.3 KiB
ReStructuredText
69 lines
2.3 KiB
ReStructuredText
MongoDB
|
|
======================
|
|
|
|
Batch process all your records using ``unstructured-ingest`` to store structured outputs locally on your filesystem and upload those local files to an MongoDB collection.
|
|
|
|
First you'll need to install the MongoDB dependencies as shown here.
|
|
|
|
.. code:: shell
|
|
|
|
pip install "unstructured[mongodb]"
|
|
|
|
Run Locally
|
|
-----------
|
|
The upstream connector can be any of the ones supported, but for convenience here, showing a sample command using the
|
|
upstream local connector.
|
|
|
|
.. tabs::
|
|
|
|
.. tab:: Shell
|
|
|
|
.. code:: shell
|
|
|
|
unstructured-ingest \
|
|
local \
|
|
--input-path example-docs/fake-memo.pdf \
|
|
--anonymous \
|
|
--output-dir local-output-to-mongo \
|
|
--num-processes 2 \
|
|
--verbose \
|
|
--strategy fast \
|
|
mongodb \
|
|
--uri "$MONGODB_URI" \
|
|
--database "$MONGODB_DATABASE_NAME" \
|
|
--collection "$DESTINATION_MONGO_COLLECTION"
|
|
|
|
.. tab:: Python
|
|
|
|
.. code:: python
|
|
|
|
import os
|
|
|
|
from unstructured.ingest.interfaces import PartitionConfig, ProcessorConfig, ReadConfig
|
|
from unstructured.ingest.runner import LocalRunner
|
|
|
|
if __name__ == "__main__":
|
|
runner = LocalRunner(
|
|
processor_config=ProcessorConfig(
|
|
verbose=True,
|
|
output_dir="local-output-to-mongo",
|
|
num_processes=2,
|
|
),
|
|
read_config=ReadConfig(),
|
|
partition_config=PartitionConfig(),
|
|
writer_type="mongodb",
|
|
writer_kwargs={
|
|
"uri": os.getenv("MONGODB_URI"),
|
|
"database": os.getenv("MONGODB_DATABASE_NAME"),
|
|
"collection": os.getenv("DESTINATION_MONGO_COLLECTION")
|
|
}
|
|
)
|
|
runner.run(
|
|
input_path="example-docs/fake-memo.pdf",
|
|
)
|
|
|
|
|
|
For a full list of the options the CLI accepts check ``unstructured-ingest <upstream connector> mongodb --help``.
|
|
|
|
NOTE: Keep in mind that you will need to have all the appropriate extras and dependencies for the file types of the documents contained in your data storage platform if you're running this locally. You can find more information about this in the `installation guide <https://unstructured-io.github.io/unstructured/installing.html>`_.
|