Read all objects
Weaviate provides the necessary APIs to iterate through all your data. This is useful when you want to manually copy/migrate your data (and vector embeddings) from one place to another.
This is done with the help of the after operator, also called the cursor API.
Read object properties and ids
Section titled “Read object properties and ids”The following code iterates through all objects, providing the properties and id for each object.
collection = client.collections.use("WineReview")for item in collection.iterator(): print(item.uuid, item.properties)const myCollection = client.collections.use("WineReview");
for await (let item of myCollection.iterator()) {
console.log(item.uuid, item.properties);
}sourceClient, err := weaviate.NewClient(weaviate.Config{ Scheme: "https", Host: "WEAVIATE_INSTANCE_URL", // Replace WEAVIATE_INSTANCE_URL with your instance URL AuthConfig: auth.ApiKey{ Value: "YOUR-WEAVIATE-API-KEY", // If auth enabled. Replace with your Weaviate instance API key. },})if err != nil { // handle error panic(err)}batchSize := 20className := "WineReview"classProperties := []string{"title"}getBatchWithCursor := func(client weaviate.Client, className string, classProperties []string, batchSize int, cursor string) (*models.GraphQLResponse, error) { fields := []graphql.Field{} for _, prop := range classProperties { fields = append(fields, graphql.Field{Name: prop}) } fields = append(fields, graphql.Field{Name: "_additional { id vector }"}) get := client.GraphQL().Get(). WithClassName(className). // Optionally retrieve the vector embedding by adding `vector` to the _additional fields WithFields(fields...). WithLimit(batchSize) if cursor != "" { return get.WithAfter(cursor).Do(context.Background()) } return get.Do(context.Background())}CollectionHandle<Map<String, Object>> collection = client.collections.use("WineReview");for (WeaviateObject<Map<String, Object>> item : collection.paginate()) { System.out.printf("%s %s\n", item.uuid(), item.properties());}var collection = client.Collections.Use("WineReview");await foreach (var item in collection.Iterator()){ Console.WriteLine($"{item.UUID} {JsonSerializer.Serialize(item.Properties)}");}Read all objects including vectors
Section titled “Read all objects including vectors”Read through all data including the vectors. (Also applicable where named vectors are used.)
collection = client.collections.use("WineReview")for item in collection.iterator( include_vector=True # If using named vectors, you can specify ones to include e.g. ['title', 'body'], or True to include all): print(item.properties) print(item.vector)const myCollection = client.collections.use("WineReview");
for await (let item of myCollection.iterator({
includeVector: true
})) {
console.log(item.uuid, item.properties);
console.log(item.vectors);
}CollectionHandle<Map<String, Object>> collection = client.collections.use("WineReview");for (WeaviateObject<Map<String, Object>> item : collection.paginate( i -> i.returnMetadata() // If using named vectors, you can specify ones to include)) { System.out.println(item.properties()); System.out.println(item.vectors());}var collection = client.Collections.Use("WineReview");await foreach ( var item in collection.Iterator( includeVectors: true // If using named vectors, you can specify ones to include )){ Console.WriteLine(JsonSerializer.Serialize(item.Properties)); Console.WriteLine(JsonSerializer.Serialize(item.Vectors));}Read all objects - Multi-tenant collections
Section titled “Read all objects - Multi-tenant collections”Iterate through all tenants and read data for each.
multi_collection = client.collections.use("WineReviewMT")# Get a list of tenantstenants = multi_collection.tenants.get()# Iterate through tenantsfor tenant_name in tenants.keys(): # Iterate through objects within each tenant for item in multi_collection.with_tenant(tenant_name).iterator(): print(f"{tenant_name}: {item.properties}")const multiCollection = client.collections.use("WineReviewMT");
const tenants = await multiCollection.tenants.get()
for (let tenantName in tenants) {
for await (let item of multiCollection.withTenant(tenantName).iterator()) {
console.log(`${tenantName}:`, item.properties);
}
}CollectionHandle<Map<String, Object>> multiCollection = client.collections.use("WineReviewMT");// Get a list of tenantsvar tenants = multiCollection.tenants.get();// Iterate through tenantsfor (Tenant tenant : tenants) { // Iterate through objects within each tenant for (WeaviateObject<Map<String, Object>> item : multiCollection .withTenant(tenant.name()) .paginate()) { System.out.printf("%s: %s\n", tenant.name(), item.properties()); }}var multiCollection = client.Collections.Use("WineReviewMT");// Get a list of tenantsvar tenants = await multiCollection.Tenants.List();// Iterate through tenantsforeach (var tenant in tenants){ // Iterate through objects within each tenant var tenantCollection = multiCollection.WithTenant(tenant.Name); await foreach (var item in tenantCollection.Iterator()) { Console.WriteLine($"{tenant.Name}: {JsonSerializer.Serialize(item.Properties)}"); }}Related pages
Section titled “Related pages”- Connect to Weaviate
- How-to: Read objects
- References: GraphQL - Additional Operators
- Manage data: multi-tenancy operations
Questions and feedback
Section titled “Questions and feedback”Have a question or feedback? Here's how to reach us.