Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1046

Type-safe $set with positional operator "$"

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.9.2
    • Component/s: API
    • Fully Compatible

      Currently the only way to use a positional operator & for updating a field in embedded array is to use the not type safe Update.Set with manually constructing the statement like:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Update.Set("MyArray.$.Value", newVal);
      

      A method can be added to the generic Update<TDocument> and UpdateBuilder<TDocument> to avoid hard-codding strings (there is already similar approach with Query<T>.ElemMatch):

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Update<MyDocument>.SetPositional(d => d.MyArray, a => a.Value, newVal);
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            sunnybg Svetoslav Milenov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: