# Says collection exist on insertion even

**URL:** <https://forum.weaviate.io/t/says-collection-exist-on-insertion-even/9667>\
**Category:** General\
**Created:** [January 10, 2025, 3:53pm UTC](https://forum.weaviate.io/t/says-collection-exist-on-insertion-even/9667 "2025-01-10T15:53:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Ashir](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/muhammad_ashir/32/2644_2.png) [@Muhammad\_Ashir](https://forum.weaviate.io/u/Muhammad_Ashir)\
**Post date:** [January 10, 2025, 3:53pm UTC](https://forum.weaviate.io/t/says-collection-exist-on-insertion-even/9667/1 "2025-01-10T15:53:49Z")

</div>

Hi I have already created collections but when I try to insert add object it says class already exist why so?

my code

```auto
collection_name = f"Collection_{request.collectionId.replace('-', '')}"
        data_row = {
            "filename": request.id,
            "filecontent": request.text,
        }
        print(f"Passing file : {request.id}")
        collection = client.collections.get(collection_name)
        with collection.batch.dynamic() as batch:
            batch.add_object(properties=data_row)
        if len(collection.batch.failed_objects) > 0:
            print(f"Failed to add objects: {collection.batch.failed_objects}")
            return {
                "status": "error",
                "message": f"Failed to add objects: {collection.batch.failed_objects}",
            }

```

error I am having

“message”: “Failed to add objects: [ErrorObject(message=‘WeaviateInsertManyAllFailedError(\‘Every object failed during insertion. Here is the set of all errors: class already exists: found similar class "Collection\_83cdb7b2569a428095e38b73e8348168"\’)’, object\_=\_BatchObject(collection=‘Collection\_83CDB7B2569A428095E38B73E8348168’, vector=None, uuid=‘dbcf23f4-bdbc-46b1-bc2f-5398eaf75dd4’, properties={‘filename’: ‘B7139300-9CC7-45F0-8096-we’, ‘filecontent’: ‘Saasdfadfs 234 234iddrsdf asdfade!’}, tenant=None, references=None, index=0, retry\_count=0), original\_uuid=None)]”

---

<div class="post-metadata">

**Author:** ![Muhammad\_Ashir](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/muhammad_ashir/32/2644_2.png) [@Muhammad\_Ashir](https://forum.weaviate.io/u/Muhammad_Ashir)\
**Post date:** [January 10, 2025, 3:54pm UTC](https://forum.weaviate.io/t/says-collection-exist-on-insertion-even/9667/2 "2025-01-10T15:54:59Z")

</div>

creating collections like this

```auto
collection_name = 'Collection_' + request.id.replace('-', '')
        client.collections.create(
            collection_name,
            vectorizer_config=[
                Configure.NamedVectors.text2vec_transformers(
                    name="filename", source_properties=["filecontent"]
                )
            ],
        )

```

---

<div class="post-metadata">

**Author:** ![Shahin](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/shahin/32/7944_2.png) [@Shahin](https://forum.weaviate.io/u/Shahin)\
**Post date:** [January 14, 2025, 11:00am UTC](https://forum.weaviate.io/t/says-collection-exist-on-insertion-even/9667/3 "2025-01-14T11:00:58Z")

</div>

Good morning @Muhammad_Ashir,

I hope you’re having a great day!

Looking at the error, it seems there might be an issue in the logic, as you’re attempting to insert the same class again.

I recommend using the exists() function in the client to handle this dynamically.

```auto
col = client.collections.get("<COL_NAME>").exists()
if col:
    print("Collection exists")
else:
    print("Collection does not exist")

```

This way, you can check if the collection already exists before trying to create or insert data into it.

Additionally, there is check on objects which can be beneficial for you:

> **[Read objects | Weaviate](https://weaviate.io/developers/weaviate/manage-data/read#check-object-existence)**
>
> Instead of querying your database, you can use an ID to retrieve individual objects.

`<VAR> = <COL_NAME>.data.exists(object_uuid)`

Hope this helps!

Regards,  
Mohamed Shahin,  
Weaviate Support Engineer
