# Any way add new object into database

**URL:** <https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550>\
**Category:** Support\
**Created:** [February 23, 2024, 3:10am UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550 "2024-02-23T03:10:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhenzhao\_Tu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/zhenzhao_tu/32/812_2.png) [@Zhenzhao\_Tu](https://forum.weaviate.io/u/Zhenzhao_Tu)\
**Post date:** [February 23, 2024, 3:10am UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/1 "2024-02-23T03:10:18Z")

</div>

### Description

I am trying to add a feature that allow user upload good “prompt” and “answer” into set up class. Assume I have only two properties: “Prompt” and “Answer”, and is any option that allow me directly add new object “new prompt” and “new answer” into my class.

I know there is an alternative way is updating my dataset then reset the class, but that takes long time and not ‘smoothly’.

### Server Setup Information

- Weaviate Server Version: v3
- Deployment Method: Weaviate Cloud
- Client Language and Version: Python and v3.26.2

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [February 23, 2024, 12:15pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/2 "2024-02-23T12:15:31Z")

</div>

Hi @Zhenzhao_Tu !

You mean adding new properties?

If that’s the case, yes, you can add new properties.

Not sure I understood your issue ☹

---

<div class="post-metadata">

**Author:** ![Zhenzhao\_Tu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/zhenzhao_tu/32/812_2.png) [@Zhenzhao\_Tu](https://forum.weaviate.io/u/Zhenzhao_Tu)\
**Post date:** [February 23, 2024, 6:20pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/3 "2024-02-23T18:20:26Z")

</div>

Sorry about the confusion,

I got only two properties in my scheme class: “prompt”, “answer”. Now I want to add one new objects (“new prompt”, “new answer”) into my existing class. Does that possible?

Or in the other words, it’s like add a new row into dataset then reset the weavite database so we can add new objects in the db.

I am not sure it’s making sense

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [February 23, 2024, 7:57pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/4 "2024-02-23T19:57:42Z")

</div>

Hi!

You can add new objects (or rows) in you collection (schema/class/“table”).

Consider the following code that creates the collection you described:

```auto
import weaviate
from weaviate import classes as wvc
client = weaviate.connect_to_local()

collection = client.collections.create(
    name="MyCollection",
    vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
    properties=[
        wvc.config.Property(
            name="prompt",
            data_type=wvc.config.DataType.TEXT
        ),
        wvc.config.Property(
            name="answer",
            data_type=wvc.config.DataType.TEXT
        )
    ]
)

```

Now you can get that collection, and add objects to it:

```auto
collection = client.collections.get("MyCollection")
collection.data.insert({"prompt": "New Prompt", "answer": "New Answer"})

```

You can now retrieve those objects

```auto
query = collection.query.fetch_objects()
print(
    [item.properties for item in query.objects]
)

```

Let me know if this is what you want 🙂

---

<div class="post-metadata">

**Author:** ![Zhenzhao\_Tu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/zhenzhao_tu/32/812_2.png) [@Zhenzhao\_Tu](https://forum.weaviate.io/u/Zhenzhao_Tu)\
**Post date:** [February 23, 2024, 8:24pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/5 "2024-02-23T20:24:59Z")

</div>

Exactly what I need! Thanks!

---

<div class="post-metadata">

**Author:** ![Zhenzhao\_Tu](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/zhenzhao_tu/32/812_2.png) [@Zhenzhao\_Tu](https://forum.weaviate.io/u/Zhenzhao_Tu)\
**Post date:** [February 23, 2024, 8:32pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/6 "2024-02-23T20:32:54Z")

</div>

@DudaNogueira

I am also tried a way to add objects it looks like working which is different from your, can you check mine see if they are similar work thanks!

```auto
from client_setup import get_client
from weaviate.util import generate_uuid5

client = get_client()

# Create a new object
new_object = {
        "Prompt": "What is the capital of France?",
        "Answer": "Paris",
}

# define the add function
def add_object(new_object):
    new_data_uuid = generate_uuid5(new_object)

    # Add the object to Weaviate
    client.data_object.create(
            data_object=new_object,
            class_name="DSCode",
            uuid=new_data_uuid
    )

print(client.data_object.get_by_id(new_data_uuid, with_vector=False))
print(client.query.aggregate("DSCode").with_meta_count().do())

```

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [February 23, 2024, 8:49pm UTC](https://forum.weaviate.io/t/any-way-add-new-object-into-database/1550/7 "2024-02-23T20:49:24Z")

</div>

Oh, I see.

This is because you are using the python v3 syntax.

When you install the version 4.4.4 `weaviate-client` python package, you have access to both v3 and v4 syntax.

this is how you would initiate a python v3 client (in deprecation):

```auto
client = weaviate.Client("http://localhost:8080")

```

and this is how you initiate the new python v4 client:

```auto
client = weaviate.connect_to_local()

```

We strongely recommend to use the new python v4 client, as it delivers a lot of improvements.

Let me know if this helps!
