Map functions

Map Functions

Name Description
MAP Constructs a map value from a series of key-value pairs
MAP_GET Returns the value in a map given a specified key
MAP_SET Returns a copy of a map with a series of updated keys
MAP_REMOVE Returns a copy of a map with a series of keys removed
MAP_MERGE Merges a series of maps together.
CURRENT_CONTEXT Returns the current context as a map.
MAP_KEYS Returns an array of all keys in a map.
MAP_VALUES Returns an array of all values in a map.
MAP_ENTRIES Returns an array of key-value pairs of a map.

MAP

Syntax:

 map(key: STRING, value: ANY, ...) -> MAP 

Description:

Constructs a map from a series of key-value pairs.

MAP_GET

Syntax:

 map_get(map: ANY, key: STRING) -> ANY 

Description:

Returns the value in a map given a specified key. Returns an ABSENT value if the key does not exist in the map, or if the map argument is not a MAP .

Node.js
 const 
  
 result 
  
 = 
  
 await 
  
 db 
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ( 
  
 field 
 ( 
 "awards" 
 ). 
 mapGet 
 ( 
 "pulitzer" 
 ). 
 as 
 ( 
 "hasPulitzerAward" 
 ) 
  
 ) 
  
 . 
 execute 
 (); 
  

Web

 const 
  
 result 
  
 = 
  
 await 
  
 execute 
 ( 
 db 
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ( 
  
 field 
 ( 
 "awards" 
 ). 
 mapGet 
 ( 
 "pulitzer" 
 ). 
 as 
 ( 
 "hasPulitzerAward" 
 ) 
  
 ) 
 ); 
  
Swift
 let 
  
 result 
  
 = 
  
 try 
  
 await 
  
 db 
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ([ 
  
 Field 
 ( 
 "awards" 
 ). 
 mapGet 
 ( 
 "pulitzer" 
 ). 
 as 
 ( 
 "hasPulitzerAward" 
 ) 
  
 ]) 
  
 . 
 execute 
 () 
  

Kotlin

 val 
  
 result 
  
 = 
  
 db 
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ( 
  
 field 
 ( 
 "awards" 
 ). 
 mapGet 
 ( 
 "pulitzer" 
 ). 
 alias 
 ( 
 "hasPulitzerAward" 
 ) 
  
 ) 
  
 . 
 execute 
 () 
  

Java

 Task<Pipeline 
 . 
 Snapshot 
>  
 result 
  
 = 
  
 db 
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ( 
  
 field 
 ( 
 "awards" 
 ). 
 mapGet 
 ( 
 "pulitzer" 
 ). 
 alias 
 ( 
 "hasPulitzerAward" 
 ) 
  
 ) 
  
 . 
 execute 
 (); 
  
Python
 from 
  
 google.cloud.firestore_v1.pipeline_expressions 
  
 import 
 Field 
 result 
 = 
 ( 
 client 
 . 
 pipeline 
 () 
 . 
 collection 
 ( 
 "books" 
 ) 
 . 
 select 
 ( 
 Field 
 . 
 of 
 ( 
 "awards" 
 ) 
 . 
 map_get 
 ( 
 "pulitzer" 
 ) 
 . 
 as_ 
 ( 
 "hasPulitzerAward" 
 )) 
 . 
 execute 
 () 
 ) 
  
Java
 Pipeline 
 . 
 Snapshot 
  
 result 
  
 = 
  
 firestore 
  
 . 
 pipeline 
 () 
  
 . 
 collection 
 ( 
 "books" 
 ) 
  
 . 
 select 
 ( 
 mapGet 
 ( 
 field 
 ( 
 "awards" 
 ), 
  
 "pulitzer" 
 ). 
 as 
 ( 
 "hasPulitzerAward" 
 )) 
  
 . 
 execute 
 () 
  
 . 
 get 
 (); 
  

MAP_SET

Syntax:

 map_set(map: MAP, key: STRING, value: ANY, ...) -> MAP 

Description:

Returns a copy of the map value with its contents updated by a series of key-value pairs.

If the given resolves to an absent value, the associated key is removed from the map.

If the map argument is not a MAP , returns an absent value.

MAP_REMOVE

Syntax:

 map_remove(map: MAP, key: STRING...) -> MAP 

Description:

Returns a copy of the map value with a series of keys removed.

MAP_MERGE

Syntax:

 map_merge(maps: MAP...) -> MAP 

Merges the contents of 2 or more maps. If multiple maps have conflicting values, the last value is used.

CURRENT_CONTEXT

Syntax:

 current_context() -> MAP 

Returns a map consisting of all available fields in the current point of execution.

MAP_KEYS

Syntax:

 map_keys(map: MAP) -> ARRAY<STRING> 

Description:

Returns an array containing all keys of the map value.

MAP_VALUES

Syntax:

 map_values(map: MAP) -> ARRAY<ANY> 

Description:

Returns an array containing all values of the map value.

MAP_ENTRIES

Syntax:

 map_entries(map: MAP) -> ARRAY<MAP> 

Description:

Returns an array containing all key-value pairs in the map value.

Each key-value pair will be in the form of a map with two entries, k and v .

Examples:

map map_entries(map)
{} []
{"foo" : 2L} [{"k": "foo", "v" : 2L}]
{"foo" : "bar", "bar" : "foo"} [{"k": "foo", "v" : "bar" }, {"k" : "bar", "v": "foo"}]
Create a Mobile Website
View Site in Mobile | Classic
Share by: