•   about 2 years ago

'CursorNotFound' Error in Phase 1

Hi everyone,

I'm working on the first phase of a hackathon (Python version) and need help with the following function:

```python
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 6394024720294422828 not found, full error: {'ok': 0.0, 'errmsg': 'cursor id 6394024720294422828 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!

  • 2 comments

  • Manager   •   almost 2 years ago

    Hi Max, we may not be able to address highly specific questions on the building of your applications or intricacies of Phase 1 but we highly recommend joining our Devpost Discord and posting your question into our specific Microsoft Developers AI Learning tech-questions channel. We have a lot of participants on our server that can help out!

  •   •   almost 2 years ago

    I also faced similar error and after trying multiple approaches, I finally gave up to use bulk write. I used first loop to get all document ID's and then used second for loop to read record using ID and update it with vector data. This is not ideal approach but helped me to update details for all 3 collections.

Comments are closed.