@@ -112,11 +112,13 @@ class UnnestOptions:
112112 storing the original 0-based index of the element within the array.
113113 """
114114
115- def __init__ (self , index_field : str ):
116- self .index_field = index_field
115+ def __init__ (self , index_field : Field | str ):
116+ self .index_field = (
117+ index_field if isinstance (index_field , Field ) else Field .of (index_field )
118+ )
117119
118120 def __repr__ (self ):
119- return f"{ self .__class__ .__name__ } (index_field={ self .index_field !r} )"
121+ return f"{ self .__class__ .__name__ } (index_field={ self .index_field . path !r} )"
120122
121123
122124class Stage (ABC ):
@@ -258,13 +260,7 @@ def of(*documents: "BaseDocumentReference") -> "Documents":
258260 return Documents (* doc_paths )
259261
260262 def _pb_args (self ):
261- return [
262- Value (
263- array_value = {
264- "values" : [Value (string_value = path ) for path in self .paths ]
265- }
266- )
267- ]
263+ return [Value (reference_value = path ) for path in self .paths ]
268264
269265
270266class FindNearest (Stage ):
@@ -306,15 +302,23 @@ def _pb_options(self) -> dict[str, Value]:
306302class GenericStage (Stage ):
307303 """Represents a generic, named stage with parameters."""
308304
309- def __init__ (self , name : str , * params : Expr | Value ):
305+ def __init__ (
306+ self , name : str , * params : Expr | Value , options : dict [str , Expr | Value ] = {}
307+ ):
310308 super ().__init__ (name )
311309 self .params : list [Value ] = [
312310 p ._to_pb () if isinstance (p , Expr ) else p for p in params
313311 ]
312+ self .options : dict [str , Value ] = {
313+ k : v ._to_pb () if isinstance (v , Expr ) else v for k , v in options .items ()
314+ }
314315
315316 def _pb_args (self ):
316317 return self .params
317318
319+ def _pb_options (self ):
320+ return self .options
321+
318322 def __repr__ (self ):
319323 return f"{ self .__class__ .__name__ } (name='{ self .name } ')"
320324
@@ -437,7 +441,7 @@ def _pb_args(self):
437441 def _pb_options (self ):
438442 options = {}
439443 if self .options is not None :
440- options ["index_field" ] = Value ( string_value = self .options .index_field )
444+ options ["index_field" ] = self .options .index_field . _to_pb ( )
441445 return options
442446
443447
0 commit comments