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

Provide a way to compare equality of BSONValues

    XMLWordPrintableJSON

Details

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

    Description

      Even if we do extension BsonValue: Equatable {...} (which we may as well, because all of our BSON types will always be Equatable too) we can't actually make arbitrary BsonValues comparable via == because of restrictions preventing protocols from conforming to themselves, == only can only be applied to two instances of a concrete type conforming to Equatable, and not just instances of possibly different types that are both Equatable.

      However, we can provide a convenience method that takes in two arbitrary {{BsonValue}}s and compares whether they are equal. To implement that we can do something like

      switch left, right {
      case let l as Int, let r as Int: return l == r
      case let l as Double, let r as Double: return l == r
      // ... all the other bson types
      }
      

       

      We could additionally write a custom Nimble matcher that uses this, so we could do something like expect(doc["a"]).to(bsonEqual(doc["b"])).

      Attachments

        Issue Links

          Activity

            People

              may.hoque@mongodb.com May Hoque
              kaitlin.mahar@mongodb.com Kaitlin Mahar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: