Skip to main content

Read all objects

Overview

Sometimes, you may wish to list every object in a class, such as for manual backup when the backup feature is not suitable, or to export vectors or specific object properties. You may also wish to then restore these objects as well, to a different Weaviate instance for example.

The best way to do this is with the after operator, also called the cursor API.

Alternative ordering not possible

The after operator is based on the order of IDs. No other ordering of data, such as sorting or searching, is possible.

Retrieve and restore objects

Multi-tenancy

For classes where multi-tenancy is enabled, you will also need to specify the tenant name when reading or creating objects. See Manage data: multi-tenancy operations for details on how.

List every object

To list every object, use the after operator to loop through the data as shown in the example below.

The example connects to a "source" instance at https://some-endpoint.weaviate.network. It also defines a function that will fetch a group of objects (and their title property) in the WineReview class from using the ID of the last object retrieved as the cursor.

tip

To retrieve (and restore) vectors as well, include the vector parameter as shown in the highlighted lines.

collection = client.collections.get("YourName")

for item in collection.iterator():
print(item.properties)

Fetch the class definition

You can fetch the existing class definition like this:

# The example is coming soon
"Work in progress 👷🏻"

Restore to a target instance

And then restore to a target instance, by:

  • Creating the same class in the target instance using the fetched class definition, and
  • Then streaming the objects from the source instance to the target instance using batch imports.
# The example is coming soon
"Work in progress 👷🏻"

Putting it together

Putting the pieces together, the example code retrieves the WineReview class definition and objects from https://some-endpoint.weaviate.network and uses them to populate the database at https://anon-endpoint.weaviate.network:

# The example is coming soon
"Work in progress 👷🏻"