title: MongoDB aggregation Shell script to MongoC# Driver
body: <p>How can I convert this Mongo Shell script to MongoDB C# Driver?</p>
  
  <pre><code>var myItems = []
  
  var myCursor = db.Tickets.aggregate(
     [
        { $match : { TicketProjectID : 49 } },
        { $project: { TicketProjectID:1, TicketID:1, concatValue: { $concat: [ "$Status", " - ", "$Name" ] } } }
      // I will have a list of fields that I need to concatenate at run time. So C# query should support concatenation for "N" number of fields at run-time.
        //{ $group: { _id: null, count: { $sum: 1 } } }
  
     ],
        { allowDiskUse: true }
  )
  
     //This seems like a ugly performance approach when we are working against 100k results with above match
       while (myCursor.hasNext()) {
           var item = myCursor.next();
           if(item.concatValue.search(/mysearchkey/i) &gt; -1)
               {
                  myItems.push(item.TicketID)
               }
      }    
      myItems
  </code></pre>
  
  <p>or is there a better way to do the string search in concatenated projection instead of foreach in cursor, as some quires might get 50k records.</p>
  
  <p><strong>This is what I have tried so far</strong>, (Not using Aggregation)</p>
  
  <p>Note: Trimmed this code to suite for public Q&amp;A sites. So please consider this as Pseudo-code </p>
  
  <pre><code> var tickets = ticketsCollection.FindSync(filter).ToList();
                  string concatinatedValue = string.Empty;
                  foreach (var ticket in tickets)
                  {
                      foreach (var field in customFieldsForThisProject)
                          concatinatedValue += ticket[field.Replace(" ", "_")];
  
                    if(concatinatedValue.StripHtml().contains("MysearchWord"))
                   {
                     TikectIdList.Add(ticket["TicketID"])
                   }
                  }
  </code></pre>