public sealed class StructuredQuery : IMessage<StructuredQuery>, IEquatable<StructuredQuery>, IDeepCloneable<StructuredQuery>, IBufferMessage, IMessage
Reference documentation and code samples for the Firestore v1 API class StructuredQuery.
A Firestore query.
The query stages are executed in the following order:
public RepeatedField<StructuredQuery.Types.Order> OrderBy { get; }
The order to apply to the query results.
Firestore allows callers to provide a full ordering, a partial ordering, or
no ordering at all. In all cases, Firestore guarantees a stable ordering
through the following rules:
The order_by is required to reference all fields used with an
inequality filter.
All fields that are required to be in the order_by but are not already
present are appended in lexicographical ordering of the field name.
If an order on __name__ is not specified, it is appended by default.
Fields are appended with the same sort direction as the last order
specified, or 'ASCENDING' if no order was specified. For example:
ORDER BY a becomes ORDER BY a ASC, __name__ ASC
ORDER BY a DESC becomes ORDER BY a DESC, __name__ DESC
WHERE a > 1 becomes WHERE a > 1 ORDER BY a ASC, __name__ ASC
WHERE __name__ > ... AND a > 1 becomes
WHERE __name__ > ... AND a > 1 ORDER BY a ASC, __name__ ASC
public StructuredQuery.Types.Projection Select { get; set; }
Optional sub-set of the fields to return.
This acts as a [DocumentMask][google.firestore.v1.DocumentMask] over the
documents returned from a query. When not set, assumes that the caller
wants all fields returned.
A potential prefix of a position in the result set to start the query at.
The ordering of the result set is based on the ORDER BY clause of the
original query.
SELECT * FROM k WHERE a = 1 AND b > 2 ORDER BY b ASC, __name__ ASC;
This query's results are ordered by (b ASC, __name__ ASC).
Cursors can reference either the full ordering or a prefix of the location,
though it cannot reference more fields than what are in the provided
ORDER BY.
Continuing off the example above, attaching the following start cursors
will have varying impact:
START BEFORE (2, /k/123): start the query right before a = 1 AND
b > 2 AND __name__ > /k/123.
START AFTER (10): start the query right after a = 1 AND b > 10.
Unlike OFFSET which requires scanning over the first N results to skip,
a start cursor allows the query to begin at a logical position. This
position is not required to match an actual result, it will scan forward
from this position to find the next document.
Requires:
The number of values cannot be greater than the number of fields
specified in the ORDER BY clause.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis page provides documentation for the \u003ccode\u003eStructuredQuery\u003c/code\u003e class within the Google Cloud Firestore v1 API, offering a comprehensive guide to its functionality.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eStructuredQuery\u003c/code\u003e class facilitates the creation of Firestore queries with options such as filtering, ordering, limiting, and selecting specific fields, which follow a specific execution order.\u003c/p\u003e\n"],["\u003cp\u003eMultiple versions of the \u003ccode\u003eStructuredQuery\u003c/code\u003e API are listed, with the latest being version 3.10.0, and goes as low as version 2.3.0.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eStructuredQuery\u003c/code\u003e can utilize \u003ccode\u003eStartAt\u003c/code\u003e and \u003ccode\u003eEndAt\u003c/code\u003e to define the starting and ending positions within the result set, refining query results, similar to the \u003ccode\u003eOFFSET\u003c/code\u003e parameter, which determines how many documents to skip before returning the first result.\u003c/p\u003e\n"],["\u003cp\u003eThe class implements multiple interfaces, including \u003ccode\u003eIMessage\u003c/code\u003e, \u003ccode\u003eIEquatable\u003c/code\u003e, \u003ccode\u003eIDeepCloneable\u003c/code\u003e, and \u003ccode\u003eIBufferMessage\u003c/code\u003e, indicating its use within Google's Protocol Buffers framework.\u003c/p\u003e\n"]]],[],null,["# Firestore v1 API - Class StructuredQuery (3.10.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.10.0 (latest)](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.9.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.9.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.8.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.8.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.7.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.7.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.6.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.6.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.5.1](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.5.1/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.4.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.4.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.3.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.3.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.2.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.2.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.1.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.1.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [3.0.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/3.0.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [2.5.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.5.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [2.4.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.4.0/Google.Cloud.Firestore.V1.StructuredQuery)\n- [2.3.0](/dotnet/docs/reference/Google.Cloud.Firestore.V1/2.3.0/Google.Cloud.Firestore.V1.StructuredQuery) \n\n public sealed class StructuredQuery : IMessage\u003cStructuredQuery\u003e, IEquatable\u003cStructuredQuery\u003e, IDeepCloneable\u003cStructuredQuery\u003e, IBufferMessage, IMessage\n\nReference documentation and code samples for the Firestore v1 API class StructuredQuery.\n\nA Firestore query.\n\nThe query stages are executed in the following order:\n\n1. from\n2. where\n3. select\n4. order_by + start_at + end_at\n5. offset\n6. limit\n7. find_nearest \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e StructuredQuery \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[StructuredQuery](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1.StructuredQuery), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Firestore.V1](/dotnet/docs/reference/Google.Cloud.Firestore.V1/latest/Google.Cloud.Firestore.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.Firestore.V1.dll\n\nConstructors\n------------\n\n### StructuredQuery()\n\n public StructuredQuery()\n\n### StructuredQuery(StructuredQuery)\n\n public StructuredQuery(StructuredQuery other)\n\nProperties\n----------\n\n### EndAt\n\n public Cursor EndAt { get; set; }\n\nA potential prefix of a position in the result set to end the query at.\n\nThis is similar to `START_AT` but with it controlling the end position\nrather than the start position.\n\nRequires:\n\n- The number of values cannot be greater than the number of fields specified in the `ORDER BY` clause.\n\n### FindNearest\n\n public StructuredQuery.Types.FindNearest FindNearest { get; set; }\n\nOptional. A potential nearest neighbors search.\n\nApplies after all other filters and ordering.\n\nFinds the closest vector embeddings to the given query vector.\n\n### From\n\n public RepeatedField\u003cStructuredQuery.Types.CollectionSelector\u003e From { get; }\n\nThe collections to query.\n\n### Limit\n\n public int? Limit { get; set; }\n\nThe maximum number of results to return.\n\nApplies after all other constraints.\n\nRequires:\n\n- The value must be greater than or equal to zero if specified.\n\n### Offset\n\n public int Offset { get; set; }\n\nThe number of documents to skip before returning the first result.\n\nThis applies after the constraints specified by the `WHERE`, `START AT`, \\&\n`END AT` but before the `LIMIT` clause.\n\nRequires:\n\n- The value must be greater than or equal to zero if specified.\n\n### OrderBy\n\n public RepeatedField\u003cStructuredQuery.Types.Order\u003e OrderBy { get; }\n\nThe order to apply to the query results.\n\nFirestore allows callers to provide a full ordering, a partial ordering, or\nno ordering at all. In all cases, Firestore guarantees a stable ordering\nthrough the following rules:\n\n- The `order_by` is required to reference all fields used with an inequality filter.\n- All fields that are required to be in the `order_by` but are not already present are appended in lexicographical ordering of the field name.\n- If an order on `__name__` is not specified, it is appended by default.\n\nFields are appended with the same sort direction as the last order\nspecified, or 'ASCENDING' if no order was specified. For example:\n\n- `ORDER BY a` becomes `ORDER BY a ASC, __name__ ASC`\n- `ORDER BY a DESC` becomes `ORDER BY a DESC, __name__ DESC`\n- `WHERE a \u003e 1` becomes `WHERE a \u003e 1 ORDER BY a ASC, __name__ ASC`\n- `WHERE __name__ \u003e ... AND a \u003e 1` becomes `WHERE __name__ \u003e ... AND a \u003e 1 ORDER BY a ASC, __name__ ASC`\n\n### Select\n\n public StructuredQuery.Types.Projection Select { get; set; }\n\nOptional sub-set of the fields to return.\n\nThis acts as a \\[DocumentMask\\]\\[google.firestore.v1.DocumentMask\\] over the\ndocuments returned from a query. When not set, assumes that the caller\nwants all fields returned.\n\n### StartAt\n\n public Cursor StartAt { get; set; }\n\nA potential prefix of a position in the result set to start the query at.\n\nThe ordering of the result set is based on the `ORDER BY` clause of the\noriginal query. \n\n SELECT * FROM k WHERE a = 1 AND b \u003e 2 ORDER BY b ASC, __name__ ASC;\n\nThis query's results are ordered by `(b ASC, __name__ ASC)`.\n\nCursors can reference either the full ordering or a prefix of the location,\nthough it cannot reference more fields than what are in the provided\n`ORDER BY`.\n\nContinuing off the example above, attaching the following start cursors\nwill have varying impact:\n\n- `START BEFORE (2, /k/123)`: start the query right before `a = 1 AND\n b \u003e 2 AND __name__ \u003e /k/123`.\n- `START AFTER (10)`: start the query right after `a = 1 AND b \u003e 10`.\n\nUnlike `OFFSET` which requires scanning over the first N results to skip,\na start cursor allows the query to begin at a logical position. This\nposition is not required to match an actual result, it will scan forward\nfrom this position to find the next document.\n\nRequires:\n\n- The number of values cannot be greater than the number of fields specified in the `ORDER BY` clause.\n\n### Where\n\n public StructuredQuery.Types.Filter Where { get; set; }\n\nThe filter to apply."]]