序列化 Firestore 查询,以便在其他位置执行

序列化 Firestore 查询,以便在其他位置执行

代码示例

Go

如需向 Firestore 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

cities := client.CollectionGroup("cities")

// Get a partioned query for the cities collection group, with a maximum
// partition count of 10
partitionedQueries, err := cities.GetPartitionedQueries(ctx, 10)
if err != nil {
	return err
}

fmt.Printf("Collection Group query partitioned to %d queries\n", len(partitionedQueries))

query := partitionedQueries[0]

// Serialize a query created by GetPartitionedQueries
bytes, err := query.Serialize()
if err != nil {
	return fmt.Errorf("Serialize: %w", err)
}

// Deserialize a query created by Query.Serialize
deserializedQuery, err := client.CollectionGroup("").Deserialize(bytes)
if err != nil {
	return fmt.Errorf("Deserialize: %w", err)
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器