Get Documents

Open inAnthropic

Prerequisites

  • TerminusDB running locally (install guide)
  • A database with existing documents

What you'll achieve By the end of this guide, you will have retrieved documents from your TerminusDB database using the JavaScript client, the Python client, or the HTTP API.

Get a single document

Retrieve a document by its ID:

Example: TypeScript
const getDoc = async () => {
  const doc = await client.getDocument({ id: "Player/Doug" })
  console.log("Player/Doug:", doc)
}

Returns:

Example: JSON
{
  "@id"   : "Player/Doug",
  "@type" : "Player",
  "name"    : "Doug",
  "position": "Full Back"
}

Get all documents

Retrieve every document in the database:

Example: TypeScript
const getDocs = async () => {
  const documents = await client.getDocument({ as_list: "true" })
  console.log("All documents:", documents)
}

Returns:

Example: JSON
[
  {
    "@id"   : "Player/Doug",
    "@type" : "Player",
    "name"    : "Doug",
    "position": "Full Back"
  },
  {
    "@id"   : "Player/George",
    "@type" : "Player",
    "name"    : "George",
    "position": "Center Back"
  },
  {
    "@id"   : "Player/Karen",
    "@type" : "Player",
    "name"    : "Karen",
    "position": "Center Forward"
  }
]

Next steps

You've retrieved documents from TerminusDB. Next, you might want to:

Was this helpful?