Creates a field path object representing the sentinel ID of a
document. It can be used in queries to sort or filter by the document
ID. See Client#document_id.
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.new# Get a collection referencecities_col=firestore.col"cities"# Create a queryquery=cities_col.order(Google::Cloud::Firestore::FieldPath.document_id).start_at("NYC")query.getdo|city|puts"#{city.document_id} has #{city[:population]} residents."end
#initialize
definitialize(*fields)->FieldPath
Creates a field path object representing a nested field for
document data.
Parameter
fields (String, Symbol, Array<String|Symbol>) — One or more
strings representing the path of the data to select. Each field must
be provided separately.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Firestore API - Class Google::Cloud::Firestore::FieldPath (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-FieldPath)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-FieldPath)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-FieldPath)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-FieldPath)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-FieldPath)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-FieldPath)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-FieldPath)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-FieldPath)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-FieldPath)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-FieldPath)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-FieldPath)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-FieldPath)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-FieldPath) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::FieldPath.\n\nFieldPath\n---------\n\nRepresents a field path to the Firestore API. See [Client#field_path](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Client#Google__Cloud__Firestore__Client_field_path_instance_ \"Google::Cloud::Firestore::Client#field_path (method)\"). \n\nInherits\n--------\n\n- Object \n\nIncludes\n--------\n\n- Comparable\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\nuser_snap = firestore.doc(\"users/frank\").get\n\nnested_field_path = Google::Cloud::Firestore::FieldPath.new(\n :favorites, :food\n)\nuser_snap.get(nested_field_path) #=\u003e \"Pizza\"\n```\n\nMethods\n-------\n\n### .document_id\n\n def self.document_id() -\u003e FieldPath\n\nCreates a field path object representing the sentinel ID of a\ndocument. It can be used in queries to sort or filter by the document\nID. See [Client#document_id](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-Client#Google__Cloud__Firestore__Client_document_id_instance_ \"Google::Cloud::Firestore::Client#document_id (method)\"). \n**Returns**\n\n- ([FieldPath](./Google-Cloud-Firestore-FieldPath)) --- The field path object.\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\n# Get a collection reference\ncities_col = firestore.col \"cities\"\n\n# Create a query\nquery = cities_col.order(\n Google::Cloud::Firestore::FieldPath.document_id\n).start_at(\"NYC\")\n\nquery.get do |city|\n puts \"#{city.document_id} has #{city[:population]} residents.\"\nend\n```\n\n### #initialize\n\n def initialize(*fields) -\u003e FieldPath\n\nCreates a field path object representing a nested field for\ndocument data. \n**Parameter**\n\n- **fields** (String, Symbol, Array\\\u003cString\\|Symbol\\\u003e) --- One or more strings representing the path of the data to select. Each field must be provided separately. \n**Returns**\n\n- ([FieldPath](./Google-Cloud-Firestore-FieldPath)) --- The field path object. \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\n\nuser_snap = firestore.doc(\"users/frank\").get\n\nnested_field_path = Google::Cloud::Firestore::FieldPath.new(\n :favorites, :food\n)\nuser_snap.get(nested_field_path) #=\u003e \"Pizza\"\n```\n\nConstants\n---------\n\n### INVALID_FIELD_PATH_CHARS\n\n**value:**%r{\\[\\~\\*/\\[\\]\\]}\n\n### SIMPLE_FIELD_PATH_CHARS\n\n**value:**/\\\\A\\[_a-zA-Z\\]\\[_a-zA-Z0-9\\]\\*\\\\Z/"]]