Add Documents

Open inAnthropic

Prerequisites

  • TerminusDB running locally (install guide)
  • A connected client instance with a schema defined

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

After you have connected to a database and added a schema, you can insert documents that conform to the schema.

Insert a single document

Example: TypeScript
const doc = {
    "@type" : "Player",
    name    : "George",
    position: "Center Back",
}

const addDoc = async () => {
  const result = await client.addDocument(doc)
  console.log("Document added:", result)
}

Insert multiple documents

You can insert several documents in a single operation:

Example: TypeScript
const players = [
    {
        "@type" : "Player",
        name    : "George",
        position: "Center Back",
    },
    {
        "@type" : "Player",
        name    : "Doug",
        position: "Full Back",
    },
    {
        "@type" : "Player",
        name    : "Karen",
        position: "Center Forward",
    },
]

const addDocs = async () => {
  const result = await client.addDocument(players)
  console.log("Documents added:", result)
}

Insert schema documents

You can also add schema documents programmatically:

Example: TypeScript
const schema = { "@type": "Class", "@id": "Player", name: "xsd:string", position: "xsd:string" }

const addSchema = async () => {
  const result = await client.addDocument(schema, { graph_type: "schema" })
  console.log("Schema added:", result)
}

Next steps

You've inserted documents into TerminusDB. From here you can:

Was this helpful?