Um exemplo de classificação e limite de consultas do Firestore inválidos
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Um exemplo de classificação e limite de consultas do Firestore inválidos
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis page demonstrates an example of an invalid Firestore query that violates the constraint requiring range and order-by operations to be on the same field.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples in C#, Go, Java, Node.js, Python, and Ruby showcase this invalid query where filtering by population and ordering by country are attempted.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Firestore in all code samples requires setting up Application Default Credentials, with a link provided for further information on this process.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code samples will query a list of cities, and attempt to return cities with populations greater than 2,500,000, ordered by the country they are in.\u003c/p\u003e\n"]]],[],null,["# An example of an invalid order and limit Firestore query\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 // Note: This is an invalid query. It violates the constraint that range\n // and order by are required to be on the same field.\n query := cities.Where(\"population\", \"\u003e\", 2500000).OrderBy(\"country\", firestore.Asc)\n\n### Java\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 Query query = cities.whereGreaterThan(\"population\", 2500000L).orderBy(\"country\");\n\n### Node.js\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 citiesRef.where('population', '\u003e', 2500000).orderBy('country');\n\n### Python\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_ref = db.collection(\"cities\")\n query = cities_ref.where(filter=FieldFilter(\"population\", \"\u003e\", 2500000)).order_by(\n \"country\"\n )\n results = query.stream()\n\n### Ruby\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 query = cities_ref.where(\"population\", \"\u003e\", 2_500_000).order(\"country\")\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)."]]