06 Save Document Text
Persist any string to the database with one wire
- session
- document_id_link
- json
- document_id
- text_length
- success
- refresh
- document_ids
- selectable_items
- indexed_items
- item_count
This is the write node for text. "06 Save Document Text" takes any string - a generated prompt, an LLM's output, a caption, whatever - and saves it onto a document at the text field. It's the smallest possible way to get data out of your graph and into persistent storage, which makes it the workhorse for turning ComfyUI into something that remembers things between runs.
How it works
It POSTs {"text": ...} to /api/save-text/{document_id}. If the route doesn't exist (Local File Store sessions again), it falls back to the generic session save-value path, writing to the text field on the document with the default documents collection. Either way, document_id identifies the record, and you supply the text in the multiline text input (or via the document_id_link for the ID, which you should prefer over hand-typing IDs).
Outputs: json (the write response), document_id (echoes the resolved ID), text_length (how many characters were stored), success (did the write actually commit), refresh, and the document_ids list tail. If you're logging runs, text_length is a nice quick sanity check that you saved what you thought you saved.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/CentralFloridaAttorney/ComfyUI-ZMongo
Restart, or install "ComfyUI-ZMongo" from ComfyUI Manager.
Where people get burned
The key thing to internalize: this writes to a specific existing document, it doesn't create one. The default documents collection is assumed - if the document you're targeting lives in text_documents (ingest's default) or a custom collection, the generic fallback that powers local mode needs the right collection, and this node doesn't expose a collection input. In practice that means: for text you're writing by hand, save it into the default collection and keep everything in one place; if you need to attach text to an ingested document, you're better off using "06 Save Document Value" with a field_path, which is designed for that.
Second, document_id again demands a real ID, not a filename. Wire it from the guarded link outputs and you won't have to think about it. If success comes back false, read the json output - it will tell you whether the problem was a missing document, a bad ID, or a collection that doesn't match.
Last, don't confuse this with the Ingest node. Ingest extracts text from PDF/DOCX files and creates/updates a text document record with metadata and source-file info. Save Text just stuffs a raw string onto a record. Different jobs, and reaching for the wrong one is a classic beginner detour.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| session | ZMONGO_API_SESSION | — | |
| document_id | STRING | — | |
| text | STRING | — | |
| document_prefix | STRING | /documents | — |
| document_id_linkopt | * | — | |
| refresh_tokenopt | STRING | — |
Outputs (9)
| Name | Type | Description |
|---|---|---|
| json | STRING | — |
| document_id | STRING | — |
| text_length | INT | — |
| success | BOOLEAN | — |
| refresh | STRING | — |
| document_ids | * | — |
| selectable_items | * | — |
| indexed_items | STRING | — |
| item_count | INT | — |