Arithmetic functions

Preview:Firestore in Native mode (with Pipeline operations) for Enterpriseedition is subject to the "Pre-GA Offerings Terms" in the GeneralService Terms section of theService SpecificTerms. You can process personaldata for this feature as outlined in theCloud Data Processing Addendum, subjectto the obligations and restrictions described in the agreement under which youaccess Google Cloud. Pre-GA features are available "as is" and might havelimited support. For more information, see thelaunch stagedescriptions.

Arithmetic Functions

All arithmetic functions inCloud Firestore have the following behaviors:

  • Evaluates toNULL if any of the input parameters isNULL.
  • Evaluates toNaN if any of the arguments isNaN.
  • Generates an error if an overflow or underflow occurs.

Additionally, when an arithmetic function takes multiple numeric arguments ofdifferent types (for example:add(5.0, 6)),Cloud Firestore implicitlyconverts arguments to the widest input type. If onlyINT32 inputs are provided, the return type will beINT64.

NameDescription
ABSReturns the absolute value of anumber
ADDReturns the value ofx + y
SUBTRACTReturns the value ofx - y
MULTIPLYReturns the value ofx * y
DIVIDEReturns the value ofx / y
MODReturns the remainder of the division ofx / y
CEILReturns the ceiling of anumber
FLOORReturns the floor of anumber
ROUNDRounds anumber toplaces decimal places
POWReturns the value ofbase^exponent
SQRTReturns the square root of anumber
EXPReturns Euler's number raised to the power ofexponent
LNReturns the natural logarithm of anumber
LOGReturns the logarithm of anumber
LOG10Returns the logarithm of anumber to base10
RANDReturns a pseudo-random floating point number

ABS

Syntax:

abs[N <: INT32 | INT64 | FLOAT64](number: N) -> N

Description:

Returns the absolute value of anumber.

  • Throws an error when the function would overflow anINT32 orINT64 value.

Examples:

numberabs(number)
1010
-1010
10L10L
-0.00.0
10.510.5
-10.510.5
-231[error]
-263[error]

ADD

Syntax:

add[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

Description:

Returns the value ofx + y.

Examples:

xyadd(x, y)
20323
10.0111.0
22.52.024.5
INT64.MAX1[error]
INT64.MIN-1[error]
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("soldBooks").add(field("unsoldBooks")).as("totalBooks")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("soldBooks").add(Field("unsoldBooks")).as("totalBooks")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(Expression.add(field("soldBooks"),field("unsoldBooks")).alias("totalBooks")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.add(field("soldBooks"),field("unsoldBooks")).alias("totalBooks")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("soldBooks").add(Field.of("unsoldBooks")).as_("totalBooks")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(add(field("soldBooks"),field("unsoldBooks")).as("totalBooks")).execute().get();

SUBTRACT

Syntax:

subtract[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

Description:

Returns the value ofx - y.

Examples:

xysubtract(x, y)
20317
10.019.0
22.52.020.5
INT64.MAX-1[error]
INT64.MIN1[error]
Node.js
conststoreCredit=7;constresult=awaitdb.pipeline().collection("books").select(field("price").subtract(constant(storeCredit)).as("totalCost")).execute();

Web

conststoreCredit=7;constresult=awaitexecute(db.pipeline().collection("books").select(field("price").subtract(constant(storeCredit)).as("totalCost")));
Swift
letstoreCredit=7letresult=tryawaitdb.pipeline().collection("books").select([Field("price").subtract(Constant(storeCredit)).as("totalCost")]).execute()

Kotlin

valstoreCredit=7valresult=db.pipeline().collection("books").select(Expression.subtract(field("price"),storeCredit).alias("totalCost")).execute()

Java

intstoreCredit=7;Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.subtract(field("price"),storeCredit).alias("totalCost")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldstore_credit=7result=(client.pipeline().collection("books").select(Field.of("price").subtract(store_credit).as_("totalCost")).execute())
Java
intstoreCredit=7;Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(subtract(field("price"),storeCredit).as("totalCost")).execute().get();

MULTIPLY

Syntax:

multiply[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

Description:

Returns the value ofx * y.

Examples:

xymultiply(x, y)
20360
10.0110.0
22.52.045.0
INT64.MAX2[error]
INT64.MIN2[error]
FLOAT64.MAXFLOAT64.MAX+inf
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("price").multiply(field("soldBooks")).as("revenue")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("price").multiply(field("soldBooks")).as("revenue")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("price").multiply(Field("soldBooks")).as("revenue")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(Expression.multiply(field("price"),field("soldBooks")).alias("revenue")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.multiply(field("price"),field("soldBooks")).alias("revenue")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("price").multiply(Field.of("soldBooks")).as_("revenue")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(multiply(field("price"),field("soldBooks")).as("revenue")).execute().get();

DIVIDE

Syntax:

divide[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

Description:

Returns the value ofx / y. Integer division is truncated.

Examples:

xydivide(x, y)
2036
10.033.333...
22.5211.25
100[error]
1.00.0+inf
-1.00.0-inf
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("ratings").divide(field("soldBooks")).as("reviewRate")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("ratings").divide(field("soldBooks")).as("reviewRate")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("ratings").divide(Field("soldBooks")).as("reviewRate")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(Expression.divide(field("ratings"),field("soldBooks")).alias("reviewRate")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.divide(field("ratings"),field("soldBooks")).alias("reviewRate")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("ratings").divide(Field.of("soldBooks")).as_("reviewRate")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(divide(field("ratings"),field("soldBooks")).as("reviewRate")).execute().get();

MOD

Syntax:

mod[N <: INT32 | INT64 | FLOAT64](x: N, y: N) -> N

Description:

Returns the remainder ofx / y.

  • Throws anerror wheny is zero for integer types (INT64).
  • ReturnsNaN wheny is zero for float types (FLOAT64).

Examples:

xymod(x, y)
2032
-103-1
10-31
-10-3-1
1010
22.520.5
22.50.0NaN
250[error]
Node.js
constdisplayCapacity=1000;constresult=awaitdb.pipeline().collection("books").select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks")).execute();

Web

constdisplayCapacity=1000;constresult=awaitexecute(db.pipeline().collection("books").select(field("unsoldBooks").mod(constant(displayCapacity)).as("warehousedBooks")));
Swift
letdisplayCapacity=1000letresult=tryawaitdb.pipeline().collection("books").select([Field("unsoldBooks").mod(Constant(displayCapacity)).as("warehousedBooks")]).execute()

Kotlin

valdisplayCapacity=1000valresult=db.pipeline().collection("books").select(Expression.mod(field("unsoldBooks"),displayCapacity).alias("warehousedBooks")).execute()

Java

intdisplayCapacity=1000;Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.mod(field("unsoldBooks"),displayCapacity).alias("warehousedBooks")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFielddisplay_capacity=1000result=(client.pipeline().collection("books").select(Field.of("unsoldBooks").mod(display_capacity).as_("warehousedBooks")).execute())
Java
intdisplayCapacity=1000;Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(mod(field("unsoldBooks"),displayCapacity).as("warehousedBooks")).execute().get();

CEIL

Syntax:

ceil[N <: INT32 | INT64 | FLOAT64](number: N) -> N

Description:

Returns the smallest integer value that isn't less thannumber.

Examples:

numberceil(number)
2020
1010
00
24L24L
-0.4-0.0
0.41.0
22.523.0
+inf+inf
-inf-inf
Node.js
constbooksPerShelf=100;constresult=awaitdb.pipeline().collection("books").select(field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves")).execute();

Web

constbooksPerShelf=100;constresult=awaitexecute(db.pipeline().collection("books").select(field("unsoldBooks").divide(constant(booksPerShelf)).ceil().as("requiredShelves")));
Swift
letbooksPerShelf=100letresult=tryawaitdb.pipeline().collection("books").select([Field("unsoldBooks").divide(Constant(booksPerShelf)).ceil().as("requiredShelves")]).execute()

Kotlin

valbooksPerShelf=100valresult=db.pipeline().collection("books").select(Expression.divide(field("unsoldBooks"),booksPerShelf).ceil().alias("requiredShelves")).execute()

Java

intbooksPerShelf=100;Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.divide(field("unsoldBooks"),booksPerShelf).ceil().alias("requiredShelves")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldbooks_per_shelf=100result=(client.pipeline().collection("books").select(Field.of("unsoldBooks").divide(books_per_shelf).ceil().as_("requiredShelves")).execute())
Java
intbooksPerShelf=100;Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(ceil(divide(field("unsoldBooks"),booksPerShelf)).as("requiredShelves")).execute().get();

FLOOR

Syntax:

floor[N <: INT32 | INT64 | FLOAT64](number: N) -> N

Description:

Returns the largest integer value that isn't greater thannumber.

Examples:

numberfloor(number)
2020
1010
00
21474836482147483648
-0.4-1.0
0.40.0
22.522.0
+inf+inf
-inf-inf
Node.js
constresult=awaitdb.pipeline().collection("books").addFields(field("wordCount").divide(field("pages")).floor().as("wordsPerPage")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").addFields(field("wordCount").divide(field("pages")).floor().as("wordsPerPage")));
Swift
letresult=tryawaitdb.pipeline().collection("books").addFields([Field("wordCount").divide(Field("pages")).floor().as("wordsPerPage")]).execute()

Kotlin

valresult=db.pipeline().collection("books").addFields(Expression.divide(field("wordCount"),field("pages")).floor().alias("wordsPerPage")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").addFields(Expression.divide(field("wordCount"),field("pages")).floor().alias("wordsPerPage")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").add_fields(Field.of("wordCount").divide(Field.of("pages")).floor().as_("wordsPerPage")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").addFields(floor(divide(field("wordCount"),field("pages"))).as("wordsPerPage")).execute().get();

ROUND

Syntax:

round[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N) -> Nround[N <: INT32 | INT64 | FLOAT64 | DECIMAL128](number: N, places: INT64) -> N

Description:

Roundsplaces digits off anumber. Rounds digits from the right of the decimal point ifplaces is positive, and to the left of the decimal point if it is negative.

  • If onlynumber is provided, rounds to the nearest whole value.
  • Rounds away from zero in halfway cases.
  • Anerror is thrown if rounding with a negativeplaces value results in overflow.

Examples:

numberplacesround(number, places)
15.5016.0
-15.50-16.0
15115
15015
15-120
15-20
15.48924115.5
231-1-1[error]
263-1L-1[error]
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("soldBooks").multiply(field("price")).round().as("partialRevenue")).aggregate(field("partialRevenue").sum().as("totalRevenue")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("soldBooks").multiply(field("price")).round().as("partialRevenue")).aggregate(field("partialRevenue").sum().as("totalRevenue")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("soldBooks").multiply(Field("price")).round().as("partialRevenue")]).aggregate([Field("partialRevenue").sum().as("totalRevenue")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(Expression.multiply(field("soldBooks"),field("price")).round().alias("partialRevenue")).aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(Expression.multiply(field("soldBooks"),field("price")).round().alias("partialRevenue")).aggregate(AggregateFunction.sum("partialRevenue").alias("totalRevenue")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("soldBooks").multiply(Field.of("price")).round().as_("partialRevenue")).aggregate(Field.of("partialRevenue").sum().as_("totalRevenue")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(round(multiply(field("soldBooks"),field("price"))).as("partialRevenue")).aggregate(sum("partialRevenue").as("totalRevenue")).execute().get();

POW

Syntax:

pow(base: FLOAT64, exponent: FLOAT64) -> FLOAT64

Description:

Returns the valuebase raised to the power ofexponent.

  • Throws an error ifbase <= 0 andexponent is negative.

  • For anyexponent,pow(1, exponent) is 1.

  • For anybase,pow(base, 0) is 1.

Examples:

baseexponentpow(base, exponent)
238.0
2-30.125
+inf01.0
1+inf1.0
-10.5[error]
0-1[error]
Node.js
constgoogleplex={latitude:37.4221,longitude:122.0853};constresult=awaitdb.pipeline().collection("cities").addFields(field("lat").subtract(constant(googleplex.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),field("lng").subtract(constant(googleplex.longitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")).execute();

Web

constgoogleplex={latitude:37.4221,longitude:122.0853};constresult=awaitexecute(db.pipeline().collection("cities").addFields(field("lat").subtract(constant(googleplex.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),field("lng").subtract(constant(googleplex.longitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")));
Swift
letgoogleplex=CLLocation(latitude:37.4221,longitude:122.0853)letresult=tryawaitdb.pipeline().collection("cities").addFields([Field("lat").subtract(Constant(googleplex.coordinate.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),Field("lng").subtract(Constant(googleplex.coordinate.latitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")]).select([Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")]).execute()

Kotlin

valgoogleplex=GeoPoint(37.4221,-122.0853)valresult=db.pipeline().collection("cities").addFields(field("lat").subtract(googleplex.latitude).multiply(111/* km per degree */).pow(2).alias("latitudeDifference"),field("lng").subtract(googleplex.longitude).multiply(111/* km per degree */).pow(2).alias("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.alias("approximateDistanceToGoogle")).execute()

Java

GeoPointgoogleplex=newGeoPoint(37.4221,-122.0853);Task<Pipeline.Snapshot>result=db.pipeline().collection("cities").addFields(field("lat").subtract(googleplex.getLatitude()).multiply(111/* km per degree */).pow(2).alias("latitudeDifference"),field("lng").subtract(googleplex.getLongitude()).multiply(111/* km per degree */).pow(2).alias("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.alias("approximateDistanceToGoogle")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldgoogleplexLat=37.4221googleplexLng=-122.0853result=(client.pipeline().collection("cities").add_fields(Field.of("lat").subtract(googleplexLat).multiply(111)# km per degree.pow(2).as_("latitudeDifference"),Field.of("lng").subtract(googleplexLng).multiply(111)# km per degree.pow(2).as_("longitudeDifference"),).select(Field.of("latitudeDifference").add(Field.of("longitudeDifference")).sqrt()# Inaccurate for large distances or close to poles.as_("approximateDistanceToGoogle")).execute())
Java
doublegoogleplexLat=37.4221;doublegoogleplexLng=-122.0853;Pipeline.Snapshotresult=firestore.pipeline().collection("cities").addFields(pow(multiply(subtract(field("lat"),googleplexLat),111),2).as("latitudeDifference"),pow(multiply(subtract(field("lng"),googleplexLng),111),2).as("longitudeDifference")).select(sqrt(add(field("latitudeDifference"),field("longitudeDifference")))// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")).execute().get();

SQRT

Syntax:

sqrt[N <: FLOAT64 | DECIMAL128](number: N) -> N

Description:

Returns the square root of anumber.

  • Throws anerror ifnumber is negative.

Examples:

numbersqrt(number)
255.0
12.0023.464...
0.00.0
NaNNaN
+inf+inf
-inf[error]
x < 0[error]
Node.js
constgoogleplex={latitude:37.4221,longitude:122.0853};constresult=awaitdb.pipeline().collection("cities").addFields(field("lat").subtract(constant(googleplex.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),field("lng").subtract(constant(googleplex.longitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")).execute();

Web

constgoogleplex={latitude:37.4221,longitude:122.0853};constresult=awaitexecute(db.pipeline().collection("cities").addFields(field("lat").subtract(constant(googleplex.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),field("lng").subtract(constant(googleplex.longitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")));
Swift
letgoogleplex=CLLocation(latitude:37.4221,longitude:122.0853)letresult=tryawaitdb.pipeline().collection("cities").addFields([Field("lat").subtract(Constant(googleplex.coordinate.latitude)).multiply(111/* km per degree */).pow(2).as("latitudeDifference"),Field("lng").subtract(Constant(googleplex.coordinate.latitude)).multiply(111/* km per degree */).pow(2).as("longitudeDifference")]).select([Field("latitudeDifference").add(Field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")]).execute()

Kotlin

valgoogleplex=GeoPoint(37.4221,-122.0853)valresult=db.pipeline().collection("cities").addFields(field("lat").subtract(googleplex.latitude).multiply(111/* km per degree */).pow(2).alias("latitudeDifference"),field("lng").subtract(googleplex.longitude).multiply(111/* km per degree */).pow(2).alias("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.alias("approximateDistanceToGoogle")).execute()

Java

GeoPointgoogleplex=newGeoPoint(37.4221,-122.0853);Task<Pipeline.Snapshot>result=db.pipeline().collection("cities").addFields(field("lat").subtract(googleplex.getLatitude()).multiply(111/* km per degree */).pow(2).alias("latitudeDifference"),field("lng").subtract(googleplex.getLongitude()).multiply(111/* km per degree */).pow(2).alias("longitudeDifference")).select(field("latitudeDifference").add(field("longitudeDifference")).sqrt()// Inaccurate for large distances or close to poles.alias("approximateDistanceToGoogle")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldgoogleplexLat=37.4221googleplexLng=-122.0853result=(client.pipeline().collection("cities").add_fields(Field.of("lat").subtract(googleplexLat).multiply(111)# km per degree.pow(2).as_("latitudeDifference"),Field.of("lng").subtract(googleplexLng).multiply(111)# km per degree.pow(2).as_("longitudeDifference"),).select(Field.of("latitudeDifference").add(Field.of("longitudeDifference")).sqrt()# Inaccurate for large distances or close to poles.as_("approximateDistanceToGoogle")).execute())
Java
doublegoogleplexLat=37.4221;doublegoogleplexLng=-122.0853;Pipeline.Snapshotresult=firestore.pipeline().collection("cities").addFields(pow(multiply(subtract(field("lat"),googleplexLat),111),2).as("latitudeDifference"),pow(multiply(subtract(field("lng"),googleplexLng),111),2).as("longitudeDifference")).select(sqrt(add(field("latitudeDifference"),field("longitudeDifference")))// Inaccurate for large distances or close to poles.as("approximateDistanceToGoogle")).execute().get();

EXP

Syntax:

exp(exponent: FLOAT64) -> FLOAT64

Description:

Returns the value of Euler's number raised to the power ofexponent, also called the natural exponential function.

Examples:

exponentexp(exponent)
0.01.0
10e^10 (FLOAT64)
+inf+inf
-inf0
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("rating").exp().as("expRating")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("rating").exp().as("expRating")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("rating").exp().as("expRating")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(field("rating").exp().alias("expRating")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(field("rating").exp().alias("expRating")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("rating").exp().as_("expRating")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(exp(field("rating")).as("expRating")).execute().get();

LN

Syntax:

ln(number: FLOAT64) -> FLOAT64

Description:

Returns the natural logarithm ofnumber. This function is equivalent tolog(number).

Examples:

numberln(number)
10.0
2L0.693...
1.00.0
e (FLOAT64)1.0
-infNaN
+inf+inf
x <= 0[error]
Node.js
constresult=awaitdb.pipeline().collection("books").select(field("rating").ln().as("lnRating")).execute();

Web

constresult=awaitexecute(db.pipeline().collection("books").select(field("rating").ln().as("lnRating")));
Swift
letresult=tryawaitdb.pipeline().collection("books").select([Field("rating").ln().as("lnRating")]).execute()

Kotlin

valresult=db.pipeline().collection("books").select(field("rating").ln().alias("lnRating")).execute()

Java

Task<Pipeline.Snapshot>result=db.pipeline().collection("books").select(field("rating").ln().alias("lnRating")).execute();
Python
fromgoogle.cloud.firestore_v1.pipeline_expressionsimportFieldresult=(client.pipeline().collection("books").select(Field.of("rating").ln().as_("lnRating")).execute())
Java
Pipeline.Snapshotresult=firestore.pipeline().collection("books").select(ln(field("rating")).as("lnRating")).execute().get();

LOG

Syntax:

log(number: FLOAT64, base: FLOAT64) -> FLOAT64log(number: FLOAT64) -> FLOAT64

Description:

Returns the logarithm of anumber tobase.

  • If onlynumber is provided, returns the logarithm ofnumber tobase (synonymous toln(number)).

Examples:

numberbaselog(number, base)
100102.0
-infNumericNaN
Numeric.+infNaN
number <= 0Numeric[error]
Numericbase <= 0[error]
Numeric1.0[error]

LOG10

Syntax:

log10(x: FLOAT64) -> FLOAT64

Description:

Returns the logarithm of anumber to base10.

Examples:

numberlog10(number)
1002.0
-infNaN
+inf+inf
x <= 0[error]

RAND

Syntax:

rand()->FLOAT64

Description:

Return a pseudo-random floating point number, chosen uniformly between0.0 (inclusive) and1.0 (exclusive).

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.