Insert

CapyDB supports MongoDB Extended JSON and EmbJSON (CapyDB Extended JSON). This guide explains how to insert documents into CapyDB.

Example Code for insert Operation

Here's an example of how to insert documents using Python. You can insert a single document or multiple documents using the same endpoint. This example includes documents with Object IDs and EmbJSON fields:

from capydb import EmbText

docs = [{
    "name": "John Doe",
    "email": "johndoe@example.com",
    "age": 30,
    "bio": EmbText("John is a software engineer with expertise in AI.")
}]


# Sending the request
response = collection.insert(docs)

Insert Response

A successful insert operation will return the following JSON response:

{
  "inserted_ids": [
    "64d2f8f01234abcd5678ef90",
    "64d2f8f01234abcd5678ef91",
    "64d2f8f01234abcd5678ef92"
  ],
  "task_id": "abc123xyz" // or `null` if all processes were synchronously completed
}

The inserted_ids field contains the IDs of the successfully inserted documents. The task_id field will have a value if there is an asynchronous task related to EmbJSON. If task_id is null, it indicates that all processes, including embedding and indexing, were completed synchronously.

How can we improve this documentation?

Got question? Email us