Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-335

Make documents `inout` parameters for insertOne/insertMany so _ids can be added

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Jason Flax suggested we could make the documents you pass into insertOne and insertMany inout, so that we could modify them to add _ids if they are missing.

      Arguments for this:

      • if you are going to use the document after you insert it, it's nice that it is updated to contain the _id.
      • quote Jason: " on mobile apps it would be standard to maintain in-memory representations of what you're inserting. So, for a ToDo list, one might insert it into the dB, while maintaining a representation in a local array field that say, a tableview would read from. Would be too expensive to constantly be doing reads for a list that recycles its cells."

      Arguments against this:

      • You can't pass in constant documents. This may lead to users having to do things like var mutableDoc = constantDoc; try myColl.insert(mutableDoc)....
      • Users may not care about / reuse the inserted documents that often in server side apps, in which case this just makes calling the method harder with no real benefit to the user.
      • For users who generate their own _ids, we will never mutate their doc, so it may be confusing/frustrating that it's inout.
      • If you care about having the _id, it's in the InsertOneResult/InsertManyResult, and you can update your local copy yourself.
      • We aren't doing general mutation on the document, only one very specific kind, and only in some cases. Users may be confused/concerned about what we are going to do to their document.
      • If insertOne/insertMany¬†throws, it may be after we've mutated the input. Users might be confused about what state they should expect the input to be in when we throw.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              kaitlin.mahar Kaitlin Mahar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: