From 90f9208053d30b90bb7fdcc2a38de2415088db7c Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 11 Mar 2025 13:36:43 -0400 Subject: [PATCH 1/3] Set() stage builder --- source/fundamentals/builders.txt | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/source/fundamentals/builders.txt b/source/fundamentals/builders.txt index 0f2cdcc5..76fbef56 100644 --- a/source/fundamentals/builders.txt +++ b/source/fundamentals/builders.txt @@ -364,6 +364,43 @@ as a ``BsonDocument`` to the `AppendStage() method To learn more about the Aggregation Pipeline, see the :manual:`Aggregation Pipeline ` server manual page. +.. _csharp-builders-set: + +Add Fields to Collection Documents +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can add new fields to existing documents in a collection +by creating a ``$set`` stage in your aggregation pipeline. To +create a ``$set`` stage, call the ``Set()`` method on a +``PipelineStageDefinitionBuilder`` object. + +.. tip:: + + To learn more about the $set stage, see :manual:`$set ` + in the {+mdb-server+} manual. + +This example builds an aggregation pipeline that performs the following +actions: + +- Matches all documents that have a ``Name`` field value of ``"Daffodil"`` +- Adds a ``Color`` field to matching documents and sets its value to + ``"Yellow"`` + +.. code-block:: csharp + + var matchFilter = Builders.Filter.Eq(f => f.Name, "Daffodil"); + var fields = Builders.SetFields.Set("Color", "Yellow"); + + var pipeline = new EmptyPipelineDefinition() + .Match(matchFilter) + .Set(fields); + +The preceding example creates the following pipeline: + +.. code-block:: json + + [{ "$match" : { "Name" : "Daffodil" } }, { "$set" : { "Color" : "Yellow"} }] + .. _csharp-builders-out: Write Pipeline Results to a Collection From 870787f1406f931ef1bd185b0ec5fd86ad294a57 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 2 Apr 2025 10:05:43 -0400 Subject: [PATCH 2/3] color property --- source/includes/fundamentals/code-examples/builders.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/source/includes/fundamentals/code-examples/builders.cs b/source/includes/fundamentals/code-examples/builders.cs index f4942aa1..aa14ea26 100644 --- a/source/includes/fundamentals/code-examples/builders.cs +++ b/source/includes/fundamentals/code-examples/builders.cs @@ -61,5 +61,6 @@ public class Flower public List Season { get; set; } public double Stock { get; set; } public string Description { get; set; } + public string Color { get; set; } } // end-model \ No newline at end of file From 2a4bf2e3486b28d53f2a5cda67e7fb3e63d4bf45 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 10 Apr 2025 09:57:36 -0400 Subject: [PATCH 3/3] RS feedback 2 --- source/fundamentals/builders.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/source/fundamentals/builders.txt b/source/fundamentals/builders.txt index 76fbef56..23f477f0 100644 --- a/source/fundamentals/builders.txt +++ b/source/fundamentals/builders.txt @@ -366,13 +366,12 @@ To learn more about the Aggregation Pipeline, see the .. _csharp-builders-set: -Add Fields to Collection Documents -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Add Fields to Documents +~~~~~~~~~~~~~~~~~~~~~~~ -You can add new fields to existing documents in a collection -by creating a ``$set`` stage in your aggregation pipeline. To -create a ``$set`` stage, call the ``Set()`` method on a -``PipelineStageDefinitionBuilder`` object. +You can add new fields to documents by creating a ``$set`` stage in +your aggregation pipeline. To create a ``$set`` stage, call the ``Set()`` +method on a ``PipelineStageDefinitionBuilder`` object. .. tip::