@@ -599,7 +599,7 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
599
599
* // }
600
600
*
601
601
* // Emit parents as document.
602
- * firestore.pipeline().collection('people').replaceWith(field( 'parents') );
602
+ * firestore.pipeline().collection('people').replaceWith('parents');
603
603
*
604
604
* // Output
605
605
* // {
@@ -608,12 +608,50 @@ export class Pipeline implements ProtoSerializable<ProtoPipeline> {
608
608
* // }
609
609
* ```
610
610
*
611
- * @param fieldValue The {@link Field} field containing the nested map.
611
+ * @param fieldName The {@link Field} field containing the nested map.
612
612
* @return A new {@code Pipeline} object with this stage appended to the stage list.
613
613
*/
614
- replaceWith ( fieldValue : Field | string ) : Pipeline {
615
- const fieldExpr =
616
- typeof fieldValue === 'string' ? field ( fieldValue ) : fieldValue ;
614
+ replaceWith ( fieldName : string ) : Pipeline ;
615
+
616
+ /**
617
+ * Fully overwrites all fields in a document with those coming from a map.
618
+ *
619
+ * <p>This stage allows you to emit a map value as a document. Each key of the map becomes a field
620
+ * on the document that contains the corresponding value.
621
+ *
622
+ * <p>Example:
623
+ *
624
+ * ```typescript
625
+ * // Input.
626
+ * // {
627
+ * // 'name': 'John Doe Jr.',
628
+ * // 'parents': {
629
+ * // 'father': 'John Doe Sr.',
630
+ * // 'mother': 'Jane Doe'
631
+ * // }
632
+ * // }
633
+ *
634
+ * // Emit parents as document.
635
+ * firestore.pipeline().collection('people').replaceWith(map({
636
+ * foo: 'bar',
637
+ * info: {
638
+ * name: field('name')
639
+ * }
640
+ * }));
641
+ *
642
+ * // Output
643
+ * // {
644
+ * // 'father': 'John Doe Sr.',
645
+ * // 'mother': 'Jane Doe'
646
+ * // }
647
+ * ```
648
+ *
649
+ * @param expr An {@link Expr} that when returned evaluates to a map.
650
+ * @return A new {@code Pipeline} object with this stage appended to the stage list.
651
+ */
652
+ replaceWith ( expr : Expr ) : Pipeline ;
653
+ replaceWith ( value : Expr | string ) : Pipeline {
654
+ const fieldExpr = typeof value === 'string' ? field ( value ) : value ;
617
655
this . readUserData ( 'replaceWith' , fieldExpr ) ;
618
656
return this . _addStage ( new Replace ( fieldExpr , 'full_replace' ) ) ;
619
657
}
0 commit comments