序列化 Firestore 查询,以便在其他位置执行
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
序列化 Firestore 查询,以便在其他位置执行
代码示例
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code snippet demonstrates how to serialize a Firestore query for use in another location.\u003c/p\u003e\n"],["\u003cp\u003eThe code utilizes \u003ccode\u003eGetPartitionedQueries\u003c/code\u003e to create a set of partitioned queries from a Firestore collection group.\u003c/p\u003e\n"],["\u003cp\u003eIt then serializes one of these partitioned queries using the \u003ccode\u003eSerialize\u003c/code\u003e method, converting it into a byte array.\u003c/p\u003e\n"],["\u003cp\u003eThe serialized query can be deserialized back into a functional query object using the \u003ccode\u003eDeserialize\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,["# Serialize a Firestore query for execution elsewhere\n\nCode sample\n-----------\n\n### Go\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n cities := client.CollectionGroup(\"cities\")\n\n // Get a partioned query for the cities collection group, with a maximum\n // partition count of 10\n partitionedQueries, err := cities.GetPartitionedQueries(ctx, 10)\n if err != nil {\n \treturn err\n }\n\n fmt.Printf(\"Collection Group query partitioned to %d queries\\n\", len(partitionedQueries))\n\n query := partitionedQueries[0]\n\n // Serialize a query created by GetPartitionedQueries\n bytes, err := query.Serialize()\n if err != nil {\n \treturn fmt.Errorf(\"Serialize: %w\", err)\n }\n\n // Deserialize a query created by Query.Serialize\n deserializedQuery, err := client.CollectionGroup(\"\").Deserialize(bytes)\n if err != nil {\n \treturn fmt.Errorf(\"Deserialize: %w\", err)\n }\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=firestore)."]]