Max Getuba
Max Getuba

Reputation: 1

I need help solving the following error: 'CursorNotFound'

Here’s a shorter message to ask for help on Stack Overflow:


Hi everyone,

I need help with the following function:

def add_collection_content_vector_field(collection_name: str):
    '''
    Add a new field to the collection to hold the vectorized content of each document.
    '''
    collection = db[collection_name]
    bulk_operations = []
    for doc in collection.find():
        if "contentVector" in doc:
            del doc["contentVector"]

        content = json.dumps(doc, default=str)
        content_vector = generate_embeddings(content)

        bulk_operations.append(pymongo.UpdateOne(
            {"_id": doc["_id"]},
            {"$set": {"contentVector": content_vector}},
            upsert=True
        ))
    collection.bulk_write(bulk_operations)

When I run add_collection_content_vector_field("sales"), I get the following error:

CursorNotFound: cursor id <> not found, full error: {'ok': 0.0, 'errmsg': 'cursor id <> not found', 'code': 43, 'codeName': 'CursorNotFound', '$clusterTime': {'clusterTime': Timestamp(1715923790, 2), 'signature': {'hash': b'\xca\x8f9\xf0f!'\xdb\xf5r\xbb\xe0\xf4to\xcc1\x93\x8e', 'keyId': 7313113004709511172}}, 'operationTime': Timestamp(1715923790, 2)}

Any ideas on how to fix this?

Thanks!

I tried running the function add_collection_content_vector_field("sales") to add a new field to each document in the 'sales' collection. I expected the function to iterate through all documents, generate embeddings, and update each document with the new contentVector field.

However, after processing some documents, I encountered the following error:

CursorNotFound: cursor id <> not found, full error: {'ok': 0.0, 'errmsg': 'cursor id <> not found', 'code': 43, 'codeName': 'CursorNotFound', '$clusterTime': {'clusterTime': Timestamp(1715923790, 2), 'signature': {'hash': b'\xca\x8f9\xf0f!'\xdb\xf5r\xbb\xe0\xf4to\xcc1\x93\x8e', 'keyId': 7313113004709511172}}, 'operationTime': Timestamp(1715923790, 2)}

This error occurs partway through the process, preventing the function from completing.

Upvotes: 0

Views: 50

Answers (0)

Related Questions