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

Internalize Document.merge method

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 0.0.8
    • None

    Description

      Document.merge was added for internal use in MongoCollection.createIndexes, but was marked public.

      Its behavior is not consistent with other public API methods for modifying documents, in that it doesn't verify that a key doesn't already exist in the document before adding it. This makes it very fast and fine for internal usage whn we know duplicates aren't a problem, but it's not very safe for users.

      Users can already safely accomplish this in this public API by doing something like:

      var doc1 = Document()
      let doc2: Document = ["a": 1, "b": 2]
      doc2.forEach { doc1[$0.key] = $0.value } 

      Therefore, there is no need to expose this and we should make it internal rather than public.

      Additionally, it appears that the only time bson_concat returns false is if the merged documents would be over the max allowed size for a bson_t. We shouldn't rely on that always being the only reason for a false return value, but we can mention in the error message that the issue is probably related to document size. 

      Attachments

        Activity

          People

            patrick.freed@mongodb.com Patrick Freed
            kaitlin.mahar@mongodb.com Kaitlin Mahar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: