Cloud Firestore API - Class Google::Cloud::Firestore::FieldPath (v2.7.2)

Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::FieldPath.

FieldPath

Represents a field path to the Firestore API. See Client#field_path.

Inherits

  • Object

Includes

  • Comparable

Example

require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

user_snap = firestore.doc("users/frank").get

nested_field_path = Google::Cloud::Firestore::FieldPath.new(
  :favorites, :food
)
user_snap.get(nested_field_path) #=> "Pizza"

Methods

.document_id

def self.document_id() -> FieldPath

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.

Returns
Example
require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

# Get a collection reference
cities_col = firestore.col "cities"

# Create a query
query = cities_col.order(
  Google::Cloud::Firestore::FieldPath.document_id
).start_at("NYC")

query.get do |city|
  puts "#{city.document_id} has #{city[:population]} residents."
end

#initialize

def initialize(*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.
Returns
Raises
  • (ArgumentError)
Example
require "google/cloud/firestore"

firestore = Google::Cloud::Firestore.new

user_snap = firestore.doc("users/frank").get

nested_field_path = Google::Cloud::Firestore::FieldPath.new(
  :favorites, :food
)
user_snap.get(nested_field_path) #=> "Pizza"

Constants

INVALID_FIELD_PATH_CHARS

value: %r{[~*/[]]}.freeze

SIMPLE_FIELD_PATH_CHARS

value: /\A[_a-zA-Z][_a-zA-Z0-9]*\Z/.freeze